Record Class RecordedExchange

java.lang.Object
java.lang.Record
org.microproxy.extras.RecordedExchange
Record Components:
started - when the exchange started, or null if not recorded
method - the request method
url - the absolute request URL
requestHeaders - the request headers, in order
requestBody - the request body (empty if none)
status - the response status, or 0 if the exchange has no response
reason - the response reason phrase
responseHeaders - the response headers, in order
responseBody - the response body
complete - 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 Details

  • 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

      public String requestHeader(String name)
      The first value of a request header, without regard to case.
      Parameters:
      name - the header name
      Returns:
      the value, or null
    • responseHeader

      public String responseHeader(String name)
      The first value of a response header, without regard to case.
      Parameters:
      name - the header name
      Returns:
      the value, or null
    • load

      public static List<RecordedExchange> load(Path path) throws IOException
      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

      public static List<RecordedExchange> readHar(Path file) throws IOException
      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 .har file, or a zlib-compressed .zhar file
      Returns:
      the exchanges, in order
      Throws:
      IOException - if the file cannot be read or is not HAR
    • parseHar

      public static List<RecordedExchange> parseHar(String json) throws IOException
      Parses a HAR document.
      Parameters:
      json - the HAR text
      Returns:
      the exchanges, in order
      Throws:
      IOException - if the text is not HAR
    • readWarc

      public static List<RecordedExchange> readWarc(Path file) throws IOException
      Reads the exchanges of a WARC file: each response record with its request record (linked by WARC-Concurrent-To). Responses without a request record get a GET of their target URI; responses cut short (WARC-Truncated) are marked incomplete.
      Parameters:
      file - a .warc or .warc.gz file
      Returns:
      the exchanges, in the order of their responses
      Throws:
      IOException - if the file cannot be read or is not WARC
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • started

      public Instant started()
      Returns the value of the started record component.
      Returns:
      the value of the started record component
    • method

      public String method()
      Returns the value of the method record component.
      Returns:
      the value of the method record component
    • url

      public String url()
      Returns the value of the url record component.
      Returns:
      the value of the url record component
    • requestHeaders

      public List<Map.Entry<String,String>> requestHeaders()
      Returns the value of the requestHeaders record component.
      Returns:
      the value of the requestHeaders record component
    • requestBody

      public byte[] requestBody()
      Returns the value of the requestBody record component.
      Returns:
      the value of the requestBody record component
    • status

      public int status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • reason

      public String reason()
      Returns the value of the reason record component.
      Returns:
      the value of the reason record component
    • responseHeaders

      public List<Map.Entry<String,String>> responseHeaders()
      Returns the value of the responseHeaders record component.
      Returns:
      the value of the responseHeaders record component
    • responseBody

      public byte[] responseBody()
      Returns the value of the responseBody record component.
      Returns:
      the value of the responseBody record component
    • complete

      public boolean complete()
      Returns the value of the complete record component.
      Returns:
      the value of the complete record component