Class StickyCookie

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

public final class StickyCookie extends Object implements HttpFiltersSource
Remembers the cookies servers set and sends them with later requests, as mitmproxy's stickycookie, so that a session started in one client carries over to others (a browser and a command-line tool, or replayed requests).

 bootstrap.plusFiltersSource(StickyCookie.matching(FlowFilter.parse("~d example.com")));
 

Every Set-Cookie from a server goes into one jar shared by all clients, following RFC 6265: a Domain attribute must cover the server's host (else the cookie is ignored) and makes the cookie apply to its subdomains too, otherwise it applies to that host only; Path defaults to the directory of the request path; Max-Age wins over Expires, and a cookie set to expire is removed from the jar; Secure cookies only go to https URLs. Requests the filter matches get the jar's unexpired cookies for their host and path, longest paths first, added to their Cookie header; a cookie the client sends itself is kept rather than overridden. Ports are not told apart, as RFC 6265 says (mitmproxy does). Domains are not checked against the public suffix list, beyond refusing a Domain with no dot. Reads heads only.

  • Method Details

    • matching

      public static StickyCookie matching(FlowFilter filter)
      Sticky cookies for the requests filter matches (body matchers do not match).
      Parameters:
      filter - the requests that get remembered cookies
      Returns:
      the addon
    • of

      public static StickyCookie of(String filterExpression)
      Sticky cookies for the requests the expression matches, as --stickycookie takes it.
      Parameters:
      filterExpression - a flow filter expression
      Returns:
      the addon
      Throws:
      IllegalArgumentException - if the expression is invalid
    • cookies

      public Map<String,List<String>> cookies()
      The cookies the jar holds and has not seen expire, as name=value strings by domain path; for inspection.
      Returns:
      a snapshot of the jar
    • 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