Module bus.http

Class Response.Builder

java.lang.Object
org.miaixz.bus.http.Response.Builder
Enclosing class:
Response

public static class Response.Builder extends Object
A builder for creating and modifying Response instances.
  • Constructor Details

    • Builder

      public Builder()
      Default constructor that initializes an empty builder.
  • Method Details

    • request

      public Response.Builder request(Request request)
      Sets the request that initiated this response.
      Parameters:
      request - The Request object.
      Returns:
      this builder instance.
    • protocol

      public Response.Builder protocol(org.miaixz.bus.core.net.Protocol protocol)
      Sets the protocol used.
      Parameters:
      protocol - The protocol (e.g., HTTP/1.1, HTTP/2).
      Returns:
      this builder instance.
    • code

      public Response.Builder code(int code)
      Sets the HTTP status code.
      Parameters:
      code - The status code.
      Returns:
      this builder instance.
    • message

      public Response.Builder message(String message)
      Sets the HTTP status message.
      Parameters:
      message - The status message.
      Returns:
      this builder instance.
    • handshake

      public Response.Builder handshake(Handshake handshake)
      Sets the TLS handshake information.
      Parameters:
      handshake - The Handshake object, which may be null.
      Returns:
      this builder instance.
    • header

      public Response.Builder header(String name, String value)
      Sets a header, replacing any existing headers with the same name.
      Parameters:
      name - The header name.
      value - The header value.
      Returns:
      this builder instance.
    • addHeader

      public Response.Builder addHeader(String name, String value)
      Adds a header, preserving any existing headers with the same name.
      Parameters:
      name - The header name.
      value - The header value.
      Returns:
      this builder instance.
    • removeHeader

      public Response.Builder removeHeader(String name)
      Removes all headers with the given name.
      Parameters:
      name - The header name.
      Returns:
      this builder instance.
    • headers

      public Response.Builder headers(Headers headers)
      Sets all headers, replacing any existing headers.
      Parameters:
      headers - The Headers object.
      Returns:
      this builder instance.
    • body

      public Response.Builder body(ResponseBody body)
      Sets the response body.
      Parameters:
      body - The ResponseBody object, which may be null.
      Returns:
      this builder instance.
    • networkResponse

      public Response.Builder networkResponse(Response networkResponse)
      Sets the network response.
      Parameters:
      networkResponse - The network Response object, which may be null.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if networkResponse has invalid properties.
    • cacheResponse

      public Response.Builder cacheResponse(Response cacheResponse)
      Sets the cache response.
      Parameters:
      cacheResponse - The cached Response object, which may be null.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if cacheResponse has invalid properties.
    • priorResponse

      public Response.Builder priorResponse(Response priorResponse)
      Sets the prior response.
      Parameters:
      priorResponse - The prior Response object, which may be null.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if priorResponse contains a body.
    • sentRequestAtMillis

      public Response.Builder sentRequestAtMillis(long sentRequestAtMillis)
      Sets the timestamp when the request was sent.
      Parameters:
      sentRequestAtMillis - The timestamp in milliseconds.
      Returns:
      this builder instance.
    • receivedResponseAtMillis

      public Response.Builder receivedResponseAtMillis(long receivedResponseAtMillis)
      Sets the timestamp when the response headers were received.
      Parameters:
      receivedResponseAtMillis - The timestamp in milliseconds.
      Returns:
      this builder instance.
    • build

      public Response build()
      Builds a new Response instance.
      Returns:
      A new Response object.
      Throws:
      IllegalStateException - if request, protocol, or message is null, or if code is less than 0.