Class HttpFiltersChain

java.lang.Object
org.microproxy.HttpFiltersChain
All Implemented Interfaces:
HttpFiltersSource

public final class HttpFiltersChain extends Object implements HttpFiltersSource
Runs several filters sources as one, in order. For each request every source may contribute filters, and they form a pipeline:
  • Request hooks run first to last; the first short-circuit response wins and later filters do not see the request. proxyToServerFailure works the same way: the first response wins.
  • Response hooks (serverToProxyResponse, proxyToClientResponse), filterWebSocketFrame and filterWebSocketMessage also run first to last, each receiving the previous one's result; null aborts (or drops the frame or message). With filterWebSocketMessages, every message one filter returns goes through the next, in the direction it now travels.
  • Buffer sizes are the largest any filter asks for; the connect and TLS handshake timeouts are the shortest; the retry backoff is the first filter's that names one.
  • Interception needs every filter's consent (both proxyToServerAllowMitm hooks), while proxyToServerAllowOfflineMitm needs any one filter's.
  • The first filter that names a TLS identity (proxyToServerTlsIdentity) sets it.
  • Notifications go to every filter; exchangeEnded reaches every filter even when one of them throws.

So a cache placed last stores responses after earlier filters have rewritten them, and earlier filters see requests before the cache can answer them.

  • Method Details

    • of

      public static HttpFiltersSource of(HttpFiltersSource... sources)
      Chains sources, flattening nested chains.
      Parameters:
      sources - the filter sources, in execution order
      Returns:
      the combined filter source
    • sources

      public List<HttpFiltersSource> sources()
      Returns the chained sources, in order.
      Returns:
      the chained sources, in order
    • filterRequest

      public HttpFilters filterRequest(HttpRequest originalRequest, FlowContext flowContext)
      Description copied from interface: HttpFiltersSource
      Returns the filters for a request, or null to proxy it unfiltered.
      Specified by:
      filterRequest in interface HttpFiltersSource
      Parameters:
      originalRequest - a copy of the request as received from the client
      flowContext - the client connection the request arrived on
      Returns:
      the per-request filters, or null to leave the request unfiltered
    • getMaximumRequestBufferSizeInBytes

      public int getMaximumRequestBufferSizeInBytes()
      Description copied from interface: HttpFiltersSource
      When positive, request bodies are buffered (up to this many bytes) and filters receive a single FullHttpRequest. Larger requests get 413.
      Specified by:
      getMaximumRequestBufferSizeInBytes in interface HttpFiltersSource
      Returns:
      the maximum request buffer size in bytes, or zero for streaming
    • getMaximumResponseBufferSizeInBytes

      public int getMaximumResponseBufferSizeInBytes()
      Description copied from interface: HttpFiltersSource
      When positive, response bodies are buffered (up to this many bytes) and filters receive a single FullHttpResponse. Larger responses get 502.
      Specified by:
      getMaximumResponseBufferSizeInBytes in interface HttpFiltersSource
      Returns:
      the maximum response buffer size in bytes, or zero for streaming