Package org.microproxy.extras
Class MapLocal
java.lang.Object
org.microproxy.extras.MapLocal
- All Implemented Interfaces:
HttpFiltersSource
Answers requests from local files, as mitmproxy's
map_local. A rule maps URLs matching a
regular expression to a file, served for every match, or to a directory, where the part of the
URL after the match (or the regex's first group) names the file:
MapLocal.of("|example.com/static/|/srv/static", // example.com/static/app.js -> /srv/static/app.js
"|~m GET|example.com/favicon.ico|/srv/icon.ico")
Specs are [|flow-filter]|url-regex|file-or-directory, the separator being the first
character; the path must exist. For a directory, the URL's remaining path (without its query)
is percent-decoded, and name, then name/index.html are tried, then the same with
characters outside [0-9a-zA-Z-_.=(),/] replaced by _; an empty remainder serves
index.html. The response is 200 with a Content-Type guessed from the file
name. When a rule matched but none of its candidates exists, the answer is 404. Paths
that would leave the directory (.., absolute parts, or symbolic links pointing outside)
are never served, and get 404 too. Files are read whole for each response.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuildsMapLocal.static final recordOne rule: requests the filter selects whose URL contains a match ofpatternare answered frompath. -
Method Summary
Modifier and TypeMethodDescriptionstatic MapLocal.Builderbuilder()Starts a builder with no rules.filterRequest(HttpRequest originalRequest, FlowContext flowContext) Returns the filters for a request, ornullto proxy it unfiltered.static MapLocalMap local 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
Map local rules from specs.- Parameters:
specs- specs of the form[|flow-filter]|url-regex|file-or-directory- Returns:
- the addon
- Throws:
IllegalArgumentException- if a spec is invalid or its path does not exist
-
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
-