Class FlowFilter

java.lang.Object
org.microproxy.extras.FlowFilter

public final class FlowFilter extends Object
A flow filter expression, in the syntax of mitmproxy's filters, which the addons (MapLocal, MapRemote, ModifyBody, ModifyHeaders, BlockList, AntiCache, StickyCookie, HarRecorder) take to choose the exchanges they act on.
Operators
expressionmatches
~u regex, or a bare regexthe URL (absolute, https:// inside intercepted sessions)
~d regexthe request's host
~m regexthe method
~h regex, ~hq regex, ~hs regexa header line ( Name: value) of the request or the response, the request, the response
~t regex, ~tq regex, ~ts regexthe Content-Type of the request or the response, the request, the response
~b regex, ~bq regex, ~bs regexthe decoded body of the request or the response, the request, the response
~c codethe response status
~q, ~sa request without a response yet, an exchange with a response
~aan asset response: CSS, JavaScript, images, fonts
~alleverything
!x, x & y, x | y, (x)not, and, or, grouping

! binds tightest, then &, then |; expressions written next to each other are joined by "and" with the lowest precedence of all, as in mitmproxy (a b | c means a & (b | c)). Regular expressions are java.util.regex patterns, searched for anywhere in the subject, ignoring case. One that contains spaces or any of ( ) ~ ' " goes in single or double quotes; inside quotes a backslash escapes only the quote and itself, so "\d+ items" keeps its \d. Operators need spaces around them after a bare word: ~u a|b is the URL regex a|b.

Request-only addons evaluate filters before the response exists, so ~s, ~c and the response matchers are false there, as in mitmproxy. A body matcher can only be decided once its body has been buffered. matches(org.microproxy.extras.FlowFilter.Flow) counts an unknown body as not matching; mayMatch(org.microproxy.extras.FlowFilter.Flow) tells whether the filter could still match once the bodies are known, which is how the addons buffer only the exchanges a filter might select.

  • Field Details

    • ALL

      public static final FlowFilter ALL
      The filter that matches every exchange (~all).
  • Method Details

    • parse

      public static FlowFilter parse(String expression)
      Parses a filter expression.
      Parameters:
      expression - the expression, such as ~d example.com & !~m GET
      Returns:
      the parsed filter
      Throws:
      IllegalArgumentException - if the expression is empty or invalid
    • expression

      public String expression()
      Returns the expression this filter was parsed from.
      Returns:
      the expression this filter was parsed from
    • matches

      public boolean matches(FlowFilter.Flow flow)
      Whether flow matches. Body matchers whose body is not available do not match.
      Parameters:
      flow - the exchange to test
      Returns:
      whether the exchange matches
    • mayMatch

      public boolean mayMatch(FlowFilter.Flow flow)
      Whether flow could match once the bodies that are not available yet are known: false only when the parts already known rule a match out.
      Parameters:
      flow - the exchange to test, perhaps without its bodies
      Returns:
      whether the exchange might match
    • usesRequestBody

      public boolean usesRequestBody()
      Returns whether the expression looks at the request body (~b, ~bq).
      Returns:
      whether the expression looks at the request body (~b, ~bq)
    • usesResponseBody

      public boolean usesResponseBody()
      Returns whether the expression looks at the response body (~b, ~bs).
      Returns:
      whether the expression looks at the response body (~b, ~bs)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • flow

      public static FlowFilter.Flow flow(HttpRequest request, String url, HttpResponse response)
      A view of an exchange for filters. A body is available when its message is a FullHttpMessage (buffered) or declares no body; it is decoded (gzip, deflate, ...) only when a body matcher asks for it, and used as received if it cannot be decoded.
      Parameters:
      request - the request
      url - the absolute URL of the request
      response - the response, or null before there is one
      Returns:
      a view of the exchange