Package org.microproxy.extras
Class ModifyHeaders
java.lang.Object
org.microproxy.extras.ModifyHeaders
- All Implemented Interfaces:
HttpFiltersSource
Sets and removes headers, as mitmproxy's
modify_headers. Each rule names a header and a
value; on every request head, and every response head from a server, the rules whose filter
matches first remove that header, then add the value (an empty value only removes it). Filters
are checked against the message before any rule changes it, and see no bodies.
ModifyHeaders.of("|~q|User-Agent|MicroProxy", // requests only (~q: no response yet)
"|~s & ~d example.com|Server|", // responses only: remove Server
"|X-Debug|@/etc/debug-token") // both, the value read from a file
Specs are [|flow-filter]|header-name|[@]header-value, the separator being the first
character. The value takes Python's backslash escapes; @path reads it from a file, again
for each message. Without a filter a rule applies to requests and responses alike, as in
mitmproxy. RewriteRules offers the same edits from Java with URL regexes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOne rule: a header to replace on the messages a filter matches. -
Method Summary
Modifier and TypeMethodDescriptionfilterRequest(HttpRequest originalRequest, FlowContext flowContext) Returns the filters for a request, ornullto proxy it unfiltered.static ModifyHeadersHeader rules from specs.static ModifyHeadersof(List<ModifyHeaders.Rule> rules) Header rules.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
Header rules from specs.- Parameters:
specs- specs of the form[|flow-filter]|header-name|[@]header-value- Returns:
- the addon
- Throws:
IllegalArgumentException- if a spec is invalid, or names a file that cannot be read
-
of
Header rules.- Parameters:
rules- the rules, in order- Returns:
- the addon
-
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
-