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), normalized: lower-case scheme and host, no user info, no trailing dot on the host, the port as the proxy reads it (:080, :+80 and : are port 80) and dropped when it is the scheme's default, escapes of unreserved characters (letters, digits, - . _ ~) decoded and other escapes in upper-case hex, and dot segments removed from the path. Escaped / and \, ; parameters and // are left as they are. A rule that looks for something the normalized URL cannot have logs a warning when parsed
~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.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    An exchange as filters see it: the request, the response once there is one, and the bodies when they have been buffered.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final FlowFilter
    The filter that matches every exchange (~all).
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the expression this filter was parsed from.
    flow(HttpRequest request, String url, HttpResponse response)
    A view of an exchange for filters.
    boolean
    Whether flow matches.
    boolean
    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.
    static FlowFilter
    parse(String expression)
    Parses a filter expression.
    flow as URL rules see it with the query of its normalized URL decoded, in each way an origin may decode it: escapes as UTF-8 with + kept and with + as a space, each also with the query delimiters & = # ; left escaped (so [^&]* does not stop at a decoded %26 the origin reads inside one value).
     
    boolean
    Returns whether the expression looks at the request body (~b, ~bq).
    boolean
    Returns whether the expression looks at the response body (~b, ~bs).
    boolean
    Returns whether the expression has a URL rule (~u or a bare regex).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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)
    • usesUrl

      public boolean usesUrl()
      Returns whether the expression has a URL rule (~u or a bare regex).
      Returns:
      whether the expression has a URL rule (~u or a bare regex)
    • 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
    • queryDecoded

      public static List<FlowFilter.Flow> queryDecoded(FlowFilter.Flow flow)
      flow as URL rules see it with the query of its normalized URL decoded, in each way an origin may decode it: escapes as UTF-8 with + kept and with + as a space, each also with the query delimiters & = # ; left escaped (so [^&]* does not stop at a decoded %26 the origin reads inside one value). A form with a decoded line terminator is offered twice, for URL rules with . crossing it and stopping at it. Forms equal to the normalized URL or to each other are left out, so the list is empty when decoding changes nothing. Origins decode query values, so ?file=%2Ffiles%2Fx is ?file=/files/x to them; BlockList blocks when a rule matches the normalized URL or any of these forms. Only URL rules see the difference.
      Parameters:
      flow - the exchange
      Returns:
      the exchange with its query decoded for URL rules, one flow per distinct form