Record Class RecordedRequest

java.lang.Object
java.lang.Record
cloud.opencode.base.test.http.RecordedRequest
Record Components:
method - the HTTP method - HTTP 方法
path - the request path including query string - 包含查询字符串的请求路径
headers - the request headers (lowercase keys) - 请求头(键为小写)
body - the request body bytes - 请求体字节

public record RecordedRequest(String method, String path, Map<String,String> headers, byte[] body) extends Record
Recorded HTTP Request — a snapshot of an HTTP request received by TestHttpServer. 记录的 HTTP 请求 — 由 TestHttpServer 接收的 HTTP 请求快照。

Features | 主要功能:

  • HTTP request snapshot capture - HTTP请求快照捕获
  • Header and body access - 请求头和请求体访问

Usage Examples | 使用示例:

RecordedRequest req = server.recordedRequest("/api/users");
String body = req.bodyAsString();
String auth = req.header("Authorization");

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-test V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • RecordedRequest

      public RecordedRequest(String method, String path, Map<String,String> headers, byte[] body)
      Compact constructor — defensively copies the body array. 紧凑构造器 — 防御性复制请求体数组。
  • Method Details

    • body

      public byte[] body()
      Returns a defensive copy of the body bytes. 返回请求体字节的防御性副本。
      Returns:
      body bytes copy | 请求体字节副本
    • bodyAsString

      public String bodyAsString()
    • header

      public String header(String name)
    • toString

      public final 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • method

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

      public String path()
      Returns the value of the path record component.
      Returns:
      the value of the path record component
    • headers

      public Map<String,String> headers()
      Returns the value of the headers record component.
      Returns:
      the value of the headers record component