Class BlockList

java.lang.Object
org.microproxy.extras.BlockList
All Implemented Interfaces:
HttpFiltersSource

public final class BlockList extends Object implements HttpFiltersSource
Blocks requests, as mitmproxy's block_list: the first rule whose filter matches answers the request with an empty response of its status, without contacting the server. Status NO_RESPONSE (444) closes the connection without any response instead (on HTTP/2, the stream is reset).

 BlockList.of("|~d ads\\.example\\.com|404", "|~u /tracking/|444")
 

Specs are |flow-filter|status, the separator being the first character. Only heads are read, unless a filter looks at the request body (~bq).

  • Field Details

    • NO_RESPONSE

      public static final int NO_RESPONSE
      The status that means "close the connection without a response", as in mitmproxy and nginx.
      See Also:
  • Method Details

    • of

      public static BlockList of(String... specs)
      Block rules from specs.
      Parameters:
      specs - specs of the form |flow-filter|status
      Returns:
      the addon
      Throws:
      IllegalArgumentException - if a spec is invalid
    • builder

      public static BlockList.Builder builder()
      Starts a builder with no rules.
      Returns:
      a new builder
    • rules

      public List<BlockList.Rule> rules()
      Returns the rules, in order.
      Returns:
      the rules, 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