Package org.microproxy.extras
Class RewriteRules
java.lang.Object
org.microproxy.extras.RewriteRules
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuildsRewriteRules.static final classOne rewrite rule: a URL pattern plus edits. -
Method Summary
Modifier and TypeMethodDescriptionstatic RewriteRules.Builderbuilder()Starts a builder with the default settings.filterRequest(HttpRequest originalRequest, FlowContext flowContext) Returns the filters for a request, ornullto proxy it unfiltered.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.microproxy.HttpFiltersSource
getMaximumRequestBufferSizeInBytes, getMaximumResponseBufferSizeInBytes
-
Method Details
-
builder
Starts a builder with the default settings.- Returns:
- a new builder with default settings
-
filterRequest
Description copied from interface:HttpFiltersSourceReturns the filters for a request, ornullto proxy it unfiltered.- Specified by:
filterRequestin interfaceHttpFiltersSource- Parameters:
originalRequest- a copy of the request as received from the clientflowContext- the client connection the request arrived on- Returns:
- the per-request filters, or
nullto leave the request unfiltered
-