Class ModifyBody
- All Implemented Interfaces:
HttpFiltersSource
modify_body: every match of
a regular expression in the decoded body becomes the replacement, in the messages a rule's filter
selects. Request bodies are edited before the request goes on, response bodies before the
response reaches the client.
ModifyBody.of("|~bs Example|Example Domain|Rewritten Domain", // responses mentioning Example
"|~q & ~d api.example.com|\"debug\":false|\"debug\":true") // request bodies
Specs are [|flow-filter]|regex|[@]replacement, the separator being the first
character. The regex runs over the body's bytes (. matches line ends too), and the
replacement is inserted literally, with Python's backslash escapes decoded; @path reads
it from a file. Without a filter a rule edits requests and responses alike; ~q limits it
to requests (no response yet) and ~s to responses.
Only messages a rule might select are buffered: the decision is made from the heads, and a
filter that also looks at bodies (~b) gets the body buffered and then checked. Messages
whose codings cannot be decoded and event streams are never buffered. A response body larger
than ModifyBody.Builder.maxBodySize streams through unchanged; a request body that large is
answered with 413, as for any filter that buffers requests. The proxy narrows
Accept-Encoding to codings it can decode, re-applies the body's coding after editing (zstd
becomes gzip) and fixes Content-Length.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuildsModifyBody.static final classOne rule: a regular expression to replace in the bodies a filter selects. -
Method Summary
Modifier and TypeMethodDescriptionstatic ModifyBody.Builderbuilder()Starts a builder with no rules.filterRequest(HttpRequest originalRequest, FlowContext flowContext) Returns the filters for a request, ornullto proxy it unfiltered.static ModifyBodyBody rules from specs.rules()Returns the rules, in order.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
-
of
Body rules from specs.- Parameters:
specs- specs of the form[|flow-filter]|regex|[@]replacement- Returns:
- the addon
- Throws:
IllegalArgumentException- if a spec is invalid, or names a file that cannot be read
-
builder
Starts a builder with no rules.- Returns:
- a new builder
-
rules
Returns the rules, in order.- Returns:
- the rules, in order
-
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
-