Class ServerReplay
- All Implemented Interfaces:
HttpFiltersSource
server_replay. Recordings come from HAR files (HarRecorder, browsers, mitmproxy) or
WARC files (WarcRecorder):
ServerReplay replay = ServerReplay.builder()
.load(Path.of("flows.har"))
.ignoreParams("_", "cachebust")
.extra(ServerReplay.Extra.status(404)) // unmatched requests get 404 instead of the server
.build();
MicroProxy.bootstrap().withFiltersSource(replay).start();
Matching follows mitmproxy's _hash: a request matches a recording with the same
scheme, method, path, body, host, port and query parameters (in order), each part left out with
an option: ServerReplay.Builder.ignoreContent, ServerReplay.Builder.ignoreHost, ServerReplay.Builder.ignorePort,
ServerReplay.Builder.ignoreParams, ServerReplay.Builder.ignorePayloadParams (for
application/x-www-form-urlencoded bodies); ServerReplay.Builder.useHeaders adds request headers.
Requests with a body are buffered to compare it (unless the body is ignored).
Use. Each recording answers once, in recorded order, so a sequence of identical
requests gets the recorded sequence of responses; with ServerReplay.Builder.reuse every recording
keeps answering. Requests with no recording left are forwarded to the server, or, with ServerReplay.Builder.extra, killed (the connection closed) or answered with a status. Replayed responses
have their Date, Expires, Last-Modified and Set-Cookie expiry
shifted by the time since they were recorded (ServerReplay.Builder.refresh, on by default), and reach
trackers and logs as ResponseSource.REPLAY.
All recordings are held in memory. Exchanges without a response, and responses cut short when they were recorded, are not replayed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classConfigures aServerReplay.static final recordWhat happens to requests without a recording, as mitmproxy'sserver_replay_extra.static final classA response answered from a recording, which the proxy reports asResponseSource.REPLAY. -
Method Summary
Modifier and TypeMethodDescriptionstatic ServerReplay.Builderbuilder()Starts a builder with no recordings and mitmproxy's defaults.filterRequest(HttpRequest originalRequest, FlowContext flowContext) Returns the filters for a request, ornullto proxy it unfiltered.intReturns how many recorded responses are left to replay (all of them, with reuse).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 no recordings and mitmproxy's defaults.- Returns:
- a new builder
-
remaining
public int remaining()Returns how many recorded responses are left to replay (all of them, with reuse).- Returns:
- how many recorded responses are left to replay (all of them, with reuse)
-
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
-