Package org.microproxy.extras
Record Class RecordedExchange
java.lang.Object
java.lang.Record
org.microproxy.extras.RecordedExchange
- Record Components:
started- when the exchange started, or null if not recordedmethod- the request methodurl- the absolute request URLrequestHeaders- the request headers, in orderrequestBody- the request body (empty if none)status- the response status, or 0 if the exchange has no responsereason- the response reason phraseresponseHeaders- the response headers, in orderresponseBody- the response bodycomplete- whether the response body was recorded in full
public record RecordedExchange(Instant started, String method, String url, List<Map.Entry<String,String>> requestHeaders, byte[] requestBody, int status, String reason, List<Map.Entry<String,String>> responseHeaders, byte[] responseBody, boolean complete)
extends Record
A recorded exchange, read from a HAR file (as
HarRecorder, browsers and mitmproxy write
them) or a WARC file (as WarcRecorder writes them), for ServerReplay and ClientReplay.
The response's headers describe its body as stored: HAR bodies are decoded, so their
Content-Encoding is dropped; WARC bodies keep the coding they were received with. Framing
headers (Content-Length, Transfer-Encoding) are dropped, since the proxy frames
replayed messages itself.
-
Constructor Summary
ConstructorsConstructorDescriptionRecordedExchange(Instant started, String method, String url, List<Map.Entry<String, String>> requestHeaders, byte[] requestBody, int status, String reason, List<Map.Entry<String, String>> responseHeaders, byte[] responseBody, boolean complete) Checks the parts and copies the lists. -
Method Summary
Modifier and TypeMethodDescriptionbooleancomplete()Returns the value of thecompleterecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.static List<RecordedExchange> Reads exchanges from a HAR file (.har, or zlib-compressed.zhar), a WARC file (.warc,.warc.gz), or every such file in a directory (in name order).method()Returns the value of themethodrecord component.static List<RecordedExchange> Parses a HAR document.static List<RecordedExchange> Reads the entries of a HAR file.static List<RecordedExchange> Reads the exchanges of a WARC file: eachresponserecord with itsrequestrecord (linked byWARC-Concurrent-To).reason()Returns the value of thereasonrecord component.booleanReturns whether there is a complete response to replay.byte[]Returns the value of therequestBodyrecord component.requestHeader(String name) The first value of a request header, without regard to case.Returns the value of therequestHeadersrecord component.byte[]Returns the value of theresponseBodyrecord component.responseHeader(String name) The first value of a response header, without regard to case.Returns the value of theresponseHeadersrecord component.started()Returns the value of thestartedrecord component.intstatus()Returns the value of thestatusrecord component.toString()Returns a string representation of this record class.url()Returns the value of theurlrecord component.
-
Constructor Details
-
RecordedExchange
public RecordedExchange(Instant started, String method, String url, List<Map.Entry<String, String>> requestHeaders, byte[] requestBody, int status, String reason, List<Map.Entry<String, String>> responseHeaders, byte[] responseBody, boolean complete) Checks the parts and copies the lists.
-
-
Method Details
-
replayable
public boolean replayable()Returns whether there is a complete response to replay.- Returns:
- whether there is a complete response to replay
-
requestHeader
The first value of a request header, without regard to case.- Parameters:
name- the header name- Returns:
- the value, or null
-
responseHeader
The first value of a response header, without regard to case.- Parameters:
name- the header name- Returns:
- the value, or null
-
load
Reads exchanges from a HAR file (.har, or zlib-compressed.zhar), a WARC file (.warc,.warc.gz), or every such file in a directory (in name order). The format is told from the content, not the name.- Parameters:
path- a file or directory- Returns:
- the exchanges, in recorded order
- Throws:
IOException- if a file cannot be read or is in neither format
-
readHar
Reads the entries of a HAR file. Entries without a response keep status 0; responses cut short by a recorder (_truncated) are marked incomplete.- Parameters:
file- a.harfile, or a zlib-compressed.zharfile- Returns:
- the exchanges, in order
- Throws:
IOException- if the file cannot be read or is not HAR
-
parseHar
Parses a HAR document.- Parameters:
json- the HAR text- Returns:
- the exchanges, in order
- Throws:
IOException- if the text is not HAR
-
readWarc
Reads the exchanges of a WARC file: eachresponserecord with itsrequestrecord (linked byWARC-Concurrent-To). Responses without a request record get aGETof their target URI; responses cut short (WARC-Truncated) are marked incomplete.- Parameters:
file- a.warcor.warc.gzfile- Returns:
- the exchanges, in the order of their responses
- Throws:
IOException- if the file cannot be read or is not WARC
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
started
Returns the value of thestartedrecord component.- Returns:
- the value of the
startedrecord component
-
method
Returns the value of themethodrecord component.- Returns:
- the value of the
methodrecord component
-
url
Returns the value of theurlrecord component.- Returns:
- the value of the
urlrecord component
-
requestHeaders
Returns the value of therequestHeadersrecord component.- Returns:
- the value of the
requestHeadersrecord component
-
requestBody
public byte[] requestBody()Returns the value of therequestBodyrecord component.- Returns:
- the value of the
requestBodyrecord component
-
status
public int status()Returns the value of thestatusrecord component.- Returns:
- the value of the
statusrecord component
-
reason
Returns the value of thereasonrecord component.- Returns:
- the value of the
reasonrecord component
-
responseHeaders
Returns the value of theresponseHeadersrecord component.- Returns:
- the value of the
responseHeadersrecord component
-
responseBody
public byte[] responseBody()Returns the value of theresponseBodyrecord component.- Returns:
- the value of the
responseBodyrecord component
-
complete
public boolean complete()Returns the value of thecompleterecord component.- Returns:
- the value of the
completerecord component
-