Class HttpRequest

java.lang.Object
com.hedera.hashgraph.sdk.HttpRequest

public final class HttpRequest extends Object
One request handed to an HttpTransport.

Note that this is the SDK's own transport-layer type, not java.net.http.HttpRequest. A single-type import of the JDK type still wins inside a compilation unit that asks for it, so existing code is unaffected.

The url is absolute and already resolved — a transport never joins anything. Header names are lowercase, and the map is never null; an empty map is the absence of headers.

  • Method Details

    • create

      public static HttpRequest create(HttpMethod method, String url)
      Create a bodyless request.
      Parameters:
      method - the HTTP method
      url - an absolute http or https URL
      Returns:
      the new request
    • withBody

      public HttpRequest withBody(byte[] body, String contentType)
      Derive a copy carrying a body.
      Parameters:
      body - the request body; defensively copied
      contentType - the body's media type
      Returns:
      the derived request
    • withHeader

      public HttpRequest withHeader(String name, String value)
      Derive a copy carrying one more header. The name is lowercased.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      the derived request
    • withHeaders

      public HttpRequest withHeaders(Map<String,String> headers)
      Derive a copy whose headers are replaced wholesale. Names are lowercased.
      Parameters:
      headers - the headers to carry
      Returns:
      the derived request
    • withDeadline

      public HttpRequest withDeadline(@Nullable Duration deadline)
      Derive a copy bounded by a deadline.

      The deadline bounds the whole exchange, body included — not time to first byte. A transport must abandon the exchange and fail with HttpTransportErrorKind.TIMEOUT_ERROR when it elapses.

      Parameters:
      deadline - the bound, or null for no bound of the caller's own
      Returns:
      the derived request
    • getMethod

      public HttpMethod getMethod()
      Extract the HTTP method.
      Returns:
      the method
    • getUrl

      public String getUrl()
      Extract the absolute URL.
      Returns:
      the URL
    • getBody

      public byte @Nullable [] getBody()
      Extract a copy of the request body.
      Returns:
      the body, or null on a bodyless method
    • getContentType

      public @Nullable String getContentType()
      Extract the body's media type.
      Returns:
      the content type, or null on a bodyless method
    • getHeaders

      public Map<String,String> getHeaders()
      Extract the request headers, with lowercased names.
      Returns:
      an unmodifiable map, never null
    • getDeadline

      public @Nullable Duration getDeadline()
      Extract the bound on the whole exchange.
      Returns:
      the deadline, or null when the caller imposes no bound of its own
    • toString

      public String toString()
      Overrides:
      toString in class Object