Class RewriteRules

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

public final class RewriteRules extends Object implements HttpFiltersSource
Declarative request/response rewriting: an ordered list of RewriteRules.Rules, each matching URLs by regular expression and editing headers and textual response bodies. Every matching rule applies, in order.

 bootstrap.withFiltersSource(RewriteRules.builder()
         .add(RewriteRules.Rule.matching("https?://example\\.com/.*")
                 .replaceInBody("Example Domain", "Rewritten Domain")
                 .removeResponseHeader("Content-Security-Policy")
                 .setRequestHeader("X-Debug", "1"))
         .build());
 

URLs are matched in absolute form: as sent by the client, or rebuilt from the Host header (https:// inside an intercepted TLS session). Body edits apply to textual responses (HttpBodies.isText(org.microproxy.http.HttpMessage), except event streams) whose content coding can be decoded (gzip, deflate); only those responses are buffered, everything else streams. ModifyBody edits request and response bodies of any type with mitmproxy's spec syntax and filter expressions. Responses larger than RewriteRules.Builder.maxBodySize also stream through unmodified.

  • Method Details

    • builder

      public static RewriteRules.Builder builder()
      Starts a builder with the default settings.
      Returns:
      a new builder with default settings
    • 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