Class TransportRequest

java.lang.Object
org.apache.juneau.rest.client.TransportRequest

public final class TransportRequest extends Object
A fully-resolved, transport-layer HTTP request.

All values (URIs, headers, bodies) are evaluated before this object is constructed — suppliers have been invoked, null-valued parts have been filtered, and the final URI has been assembled with query parameters and path substitutions applied.

Transport implementations receive a TransportRequest and are responsible for executing it against the remote server, returning a TransportResponse.

Since:
9.2.1
  • Method Details

    • builder

    • getMethod

      public String getMethod()
      Returns the HTTP method (e.g. "GET", "POST").
      Returns:
      The method. Never null.
    • getUri

      public URI getUri()
      Returns the fully-resolved request URI, including query string.
      Returns:
      The URI. Never null.
    • getHeaders

      Returns all request headers in the order they should be sent.
      Returns:
      An unmodifiable list. Never null.
    • getFirstHeader

      Returns the first header with the given name (case-insensitive), or null if absent.
      Parameters:
      name - The header name. Must not be null.
      Returns:
      The first matching header, or null if absent.
    • getBody

      Returns the request body, or null if this is a body-less request (e.g. GET, HEAD).
      Returns:
      The body, possibly null.
    • isSafeToReplay

      public boolean isSafeToReplay()
      Returns true if this request can be transparently re-sent once after a stale-connection failure.

      A pooled keep-alive socket can be torn down by the server between requests; when a transport then reuses that socket the first write fails before any response is received (e.g. an early EOF or a NoHttpResponseException). Such a failure is safe to retry on a fresh connection only when replaying the request cannot cause a duplicate side effect, which requires both of:

      • an idempotent HTTP method (GET, HEAD, PUT, DELETE, OPTIONS, TRACE) — never POST or any other non-idempotent method, and
      • a body that is either absent or repeatable, so the exact same bytes can be written again.

      When in doubt this returns false — the caller must fail closed rather than risk double-executing a request.

      Returns:
      true if the request is provably safe to replay once.
    • getTimeout

      public Duration getTimeout()
      Returns the per-call response timeout, or null if none was set.

      A null value means the transport's own default applies. Connect timeouts remain a client-level concern. All built-in transports honor this value (JDK, Apache HttpClient 4.5/5, OkHttp, Jetty and the mock transport).

      Returns:
      The response timeout, possibly null.
    • isPolicyEnforced

      public boolean isPolicyEnforced()
      Returns true if this request originated from a @Remote/@Url call and is subject to the SSRF guardrail (see org.apache.juneau.http.remote.RemoteUrlPolicy).

      Ordinary (non-@Remote) requests built directly via RestClient.get(url) etc. are never policy-covered.

      Returns:
      true if the SSRF guardrail applies to this request.
    • isAllowPrivateUrls

      public boolean isAllowPrivateUrls()
      Returns true if the allowPrivateUrls opt-in is in effect for this request, disabling the deny-private / pin-on-connect / redirect-revalidation checks (the http/https scheme requirement still applies upstream).
      Returns:
      true if private/loopback/link-local/metadata targets are allowed for this request.
    • getAllowedAddressRanges

      Returns the per-client special-purpose address ranges that the SSRF guardrail re-permits for this request (see RestClient.Builder.allowAddressRanges(String...)); they are unioned with the "RestClient.allowAddressRanges" system property.
      Returns:
      The allowed ranges. Never null; RemoteUrlPolicy.AllowedRanges#NONE by default.
    • isSsrfGuardActive

      public boolean isSsrfGuardActive()
      Returns true if the SSRF guardrail's connect-time machinery (pin-on-connect + Juneau-controlled redirect revalidation) must be applied by the transport for this request: isPolicyEnforced() is set and isAllowPrivateUrls() is not.
      Returns:
      true if the transport must pin-on-connect and manually revalidate redirects for this request.