Module bus.http

Class Request

java.lang.Object
org.miaixz.bus.http.Request

public final class Request extends Object
An HTTP request, encapsulating all information for a single request, including the URL, method, headers, body, and tags.

Note: Instances of this class are immutable if the body is null or also immutable. The request body can, however, affect the state of the instance.

Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • url

      public UnoUrl url()
      Returns the URL for this request.
      Returns:
      The UnoUrl object.
    • method

      public String method()
      Returns the HTTP method for this request.
      Returns:
      The method name (e.g., GET, POST).
    • headers

      public Headers headers()
      Returns all headers for this request.
      Returns:
      The Headers object.
    • header

      public String header(String name)
      Returns the first header value for the given name.
      Parameters:
      name - The header name.
      Returns:
      The header value, or null if not found.
    • headers

      public List<String> headers(String name)
      Returns a list of header values for the given name.
      Parameters:
      name - The header name.
      Returns:
      A list of header values, which may be empty.
    • body

      public RequestBody body()
      Returns the request body.
      Returns:
      The RequestBody object, which may be null.
    • tag

      public Object tag()
      Returns the tag attached to this request with Object.class as the key.

      If no tag is attached, this returns null. To get a tag from a derived request, a new instance must be created with newBuilder().

      Returns:
      The tag object, which may be null.
    • tag

      public <T> T tag(Class<? extends T> type)
      Returns the tag of the specified type attached to this request.

      This uses the specified type as a key to look up a value from the tags map. The returned value will be an instance of the specified type, or null if no tag is found.

      Type Parameters:
      T - The type of the tag value.
      Parameters:
      type - The type of the tag.
      Returns:
      The tag value, which may be null.
    • newBuilder

      public Request.Builder newBuilder()
      Creates a new builder instance initialized with this request's properties.
      Returns:
      A new Request.Builder instance.
    • cacheControl

      public CacheControl cacheControl()
      Returns the cache control directives for this request.

      This returns a non-null CacheControl object even if this request does not have a "Cache-Control" header. Lazily initialized for performance.

      Returns:
      The CacheControl object.
    • isHttps

      public boolean isHttps()
      Returns true if this request uses the HTTPS protocol.
      Returns:
      true if the URL uses HTTPS.
    • toString

      public String toString()
      Returns a string representation of this request.
      Overrides:
      toString in class Object
      Returns:
      A string containing the method, URL, and tags.