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).

URL rules see the normalized URL (FlowFilter). A rule also blocks when it matches the URL with its query fully percent-decoded, with + kept or read as a space (FlowFilter.queryDecoded(org.microproxy.extras.FlowFilter.Flow)), since origins decode query values: |~u [?&]file=/files/x|403 blocks ?file=%2Ffiles%2Fx, and an allow written as |!~u ^https://example\.com/dl\?file=/ok$|403 still blocks /dl?file=%2Fok: decoding never lets more through. Write query rules in decoded form; an allow for a query that clients escape must accept both spellings (next=(/|%2F)home). A decoded form holding a line break is tried with . crossing it and stopping at it, so an allow whose . must span one writes (?s).

  • 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