Class ClientRequestBase<T extends ClientRequest<T>, R extends HttpClientResponse>

java.lang.Object
io.helidon.webclient.api.ClientRequestBase<T,R>
Type Parameters:
T - type of the request
R - type of the response
All Implemented Interfaces:
ClientRequest<T>, FullClientRequest<T>
Direct Known Subclasses:
HttpClientRequest

public abstract class ClientRequestBase<T extends ClientRequest<T>, R extends HttpClientResponse> extends Object implements FullClientRequest<T>
Abstract base implementation of an HTTP client. Provides helpful methods to handle cookies, client services etc.
  • Field Details

    • USER_AGENT_HEADER

      public static final Header USER_AGENT_HEADER
      Helidon user agent request header.
    • PROXY_CONNECTION

      public static final Header PROXY_CONNECTION
      Proxy connection header.
  • Constructor Details

    • ClientRequestBase

      protected ClientRequestBase(HttpClientConfig clientConfig, WebClientCookieManager cookieManager, String protocolId, Method method, ClientUri clientUri, Map<String,String> properties)
      Create a new request.
      Parameters:
      clientConfig - client configuration
      cookieManager - cookie manager
      protocolId - protocol identifier
      method - HTTP method
      clientUri - request URI
      properties - request properties
    • ClientRequestBase

      protected ClientRequestBase(HttpClientConfig clientConfig, WebClientCookieManager cookieManager, String protocolId, Method method, ClientUri clientUri, Boolean sendExpectContinue, Map<String,String> properties)
      Create a new request.
      Parameters:
      clientConfig - client configuration
      cookieManager - cookie manager
      protocolId - protocol identifier
      method - HTTP method
      clientUri - request URI
      sendExpectContinue - whether to send the Expect: 100-Continue header
      properties - request properties
    • ClientRequestBase

      protected ClientRequestBase(HttpClientConfig clientConfig, WebClientCookieManager cookieManager, String protocolId, Method method, ClientUri clientUri, Boolean sendExpectContinue, Map<String,String> properties, ClientUri redirectSourceUri)
      Create a new request.
      Parameters:
      clientConfig - client configuration
      cookieManager - cookie manager
      protocolId - protocol identifier
      method - HTTP method
      clientUri - request URI
      sendExpectContinue - whether to send the Expect: 100-Continue header
      properties - request properties
      redirectSourceUri - original request URI for redirect handling
    • ClientRequestBase

      protected ClientRequestBase(HttpClientConfig clientConfig, WebClientCookieManager cookieManager, String protocolId, Method method, ClientUri clientUri, Boolean sendExpectContinue, Map<String,String> properties, ClientUri redirectSourceUri, boolean crossOriginRedirect)
      Create a new request.
      Parameters:
      clientConfig - client configuration
      cookieManager - cookie manager
      protocolId - protocol identifier
      method - HTTP method
      clientUri - request URI
      sendExpectContinue - whether to send the Expect: 100-Continue header
      properties - request properties
      redirectSourceUri - original request URI for redirect handling
      crossOriginRedirect - whether a previous redirect crossed an origin boundary
  • Method Details

    • tls

      public T tls(Tls tls)
      Description copied from interface: ClientRequest
      TLS configuration for this specific request.
      Specified by:
      tls in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      tls - tls configuration
      Returns:
      updated request
    • sni

      public T sni(SniConfig sni)
      Description copied from interface: ClientRequest
      Configure client-side TLS SNI for this request.

      Request-level SNI overrides client-level SNI. A configured SNI host is also used as the TLS peer host for endpoint identification.

      Specified by:
      sni in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      sni - SNI configuration
      Returns:
      updated request
    • uri

      public T uri(URI uri)
      Description copied from interface: ClientRequest
      Configure an existing URI.
      Specified by:
      uri in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      uri - uri to resolve against base URI, or to use if absolute
      Returns:
      updated request
    • requestTarget

      public T requestTarget(HttpPrologue prologue)
      Description copied from interface: ClientRequest
      Replace the request path and query with the target from an HTTP prologue. This can be used to forward a server request using its prologue() while retaining this client's destination scheme, host, and port. The configured base path, query, fragment, and URI template are replaced; the method, headers, and URI encoding setting are unchanged.

      With URI encoding enabled (the default), the raw path and query are preserved, including percent-escape spelling, matrix parameters, query ordering, repeated parameters, and an empty query delimiter. Reading query parameters does not change the target. Explicit query parameter mutations rebuild the query; changing the path leaves an unmodified query intact. The prologue's fragment is not copied.

      Origin-form targets must start with /. For absolute-form HTTP or HTTPS targets, only the raw path and query are copied; an empty path is sent as /. Asterisk-form and authority-form targets are not supported.

      The default implementation throws UnsupportedOperationException. Implementations that support forwarding must override this method.

      Specified by:
      requestTarget in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      prologue - prologue containing the request target to forward
      Returns:
      updated request
    • address

      public T address(SocketAddress socketAddress)
      Description copied from interface: ClientRequest
      Socket address to use. This can be used to connect to a UNIX domain socket. Note that if UNIX domain socket address is configured, all other address configuration is ignored. This includes if it is configured as a base address on the client.

      An InetSocketAddress updates the logical URI host and port. A UnixDomainSocketAddress overrides the physical transport only, so the request URI, resolved against the client base URI, still provides the logical HTTP authority. For TLS over a UNIX domain socket, the resolved URI host and port are used for SNI and endpoint identification, while the UNIX domain socket path is used only for transport.

      Specified by:
      address in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      socketAddress - socket address to use, this will override any other address configuration
      Returns:
      updated request
    • uri

      public T uri(ClientUri uri)
      Description copied from interface: ClientRequest
      Configure request URI. This always replaces the existing URI (even if base URI is configured).
      Specified by:
      uri in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      uri - uri to resolve against base URI, or to use if absolute
      Returns:
      updated request
    • path

      public T path(String uri)
      Description copied from interface: ClientRequest
      Configure path to call.
      Specified by:
      path in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      uri - path
      Returns:
      updated request
    • uri

      public T uri(String uri)
      Description copied from interface: ClientRequest
      Configure URI. The string is encoded before it is resolved. To forward a server request target, use ClientRequest.requestTarget(io.helidon.http.HttpPrologue).
      Specified by:
      uri in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      uri - uri to resolve against base URI, or to use if absolute
      Returns:
      updated request
    • resolvedUri

      public ClientUri resolvedUri()
      Description copied from interface: ClientRequest
      Resolved URI that will be used to invoke this request.
      Specified by:
      resolvedUri in interface ClientRequest<T extends ClientRequest<T>>
      Returns:
      URI to invoke
    • headers

      public ClientRequestHeaders headers()
      Description copied from interface: ClientRequest
      Get a (mutable) instance of outgoing headers.
      Specified by:
      headers in interface ClientRequest<T extends ClientRequest<T>>
      Returns:
      client request headers
    • header

      public T header(Header header)
      Description copied from interface: ClientRequest
      Set an HTTP header.
      Specified by:
      header in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      header - header to set
      Returns:
      updated request
    • headers

      public T headers(Headers headers)
      Description copied from interface: ClientRequest
      Configure headers. Copy all headers from supplied Headers instance.
      Specified by:
      headers in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      headers - to copy
      Returns:
      updated request
    • headers

      public T headers(Consumer<ClientRequestHeaders> headersConsumer)
      Description copied from interface: ClientRequest
      Update headers.
      Specified by:
      headers in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      headersConsumer - consumer of client request headers
      Returns:
      updated request
    • fragment

      public T fragment(UriFragment fragment)
      Description copied from interface: ClientRequest
      Set fragment of the URI.
      Specified by:
      fragment in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      fragment - fragment
      Returns:
      updated request
    • skipUriEncoding

      public T skipUriEncoding(boolean skip)
      Description copied from interface: ClientRequest
      Disable uri encoding.
      Specified by:
      skipUriEncoding in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      skip - set to true to disable URI encoding (false by default)
      Returns:
      updated client request
    • queryParam

      public T queryParam(String name, String... values)
      Description copied from interface: ClientRequest
      Add query parameter.
      Specified by:
      queryParam in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      name - name of parameter
      values - value(s) of parameter
      Returns:
      updated request
    • property

      public T property(String propertyName, String propertyValue)
      Description copied from interface: ClientRequest
      Add a property to be used by this request.
      Specified by:
      property in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      propertyName - property name
      propertyValue - property value
      Returns:
      updated builder instance
    • pathParam

      public T pathParam(String name, String value)
      Description copied from interface: ClientRequest
      Replace a placeholder in URI with an actual value.
      Specified by:
      pathParam in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      name - name of parameter
      value - value of parameter
      Returns:
      updated request
    • followRedirects

      public T followRedirects(boolean followRedirects)
      Description copied from interface: ClientRequest
      Whether to follow redirects.
      Specified by:
      followRedirects in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      followRedirects - follow redirects
      Returns:
      updated request
    • maxRedirects

      public T maxRedirects(int maxRedirects)
      Description copied from interface: ClientRequest
      Max number of the followed redirects.
      Specified by:
      maxRedirects in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      maxRedirects - max followed redirects
      Returns:
      updated request
    • connection

      public T connection(ClientConnection connection)
      Description copied from interface: ClientRequest
      This method is for explicit connection use by this request.
      Specified by:
      connection in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      connection - connection to use for this request
      Returns:
      updated client request
    • clearConnection

      public final void clearConnection()
      Clear an internally supplied connection without changing other request state.
    • keepAlive

      public T keepAlive(boolean keepAlive)
      Description copied from interface: ClientRequest
      Whether to use keep alive with this request.
      Specified by:
      keepAlive in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      keepAlive - use keep alive
      Returns:
      updated client request
    • readTimeout

      public T readTimeout(Duration readTimeout)
      Description copied from interface: ClientRequest
      Read timeout for this request.
      Specified by:
      readTimeout in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      readTimeout - response read timeout
      Returns:
      updated client request
    • readContinueTimeout

      public T readContinueTimeout(Duration readContinueTimeout)
      Description copied from interface: ClientRequest
      Read 100-Continue timeout for this request. This read timeout is used when 100-Continue is sent by the client, before it sends an entity.
      Specified by:
      readContinueTimeout in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      readContinueTimeout - read 100-Continue timeout duration
      Returns:
      updated client request
      See Also:
    • proxy

      public T proxy(Proxy proxy)
      Description copied from interface: ClientRequest
      Proxy configuration for this specific request.
      Specified by:
      proxy in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      proxy - proxy configuration
      Returns:
      updated request
    • request

      public R request()
      Description copied from interface: ClientRequest
      Request without an entity.
      Specified by:
      request in interface ClientRequest<T extends ClientRequest<T>>
      Returns:
      response
    • requestWithoutRouteCleanup

      protected final R requestWithoutRouteCleanup()
      Submit an internal request that participates in the enclosing top-level request's selected route.
      Returns:
      response
    • submit

      public R submit(Object entity)
      Description copied from interface: ClientRequest
      Submit an entity. For HTTP/1.1 streamed entities, entity writing can run on a helper virtual thread using the current Helidon context. This includes InstanceWriter.write(java.io.OutputStream) and EntityWriter implementations without instance-writer support. The writer can prepare request headers before its first output, and this method waits for the writer to terminate, including when an early response cancels the upload. Writers must release owned resources when output fails. Custom writers must not assume caller-thread affinity or propagation of arbitrary thread-local state.
      Specified by:
      submit in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      entity - request entity
      Returns:
      response
    • outputStream

      public R outputStream(ClientRequest.OutputStreamHandler outputStreamConsumer)
      Description copied from interface: ClientRequest
      Handle output stream and submit the request. For HTTP/1.1, request headers are sent before invoking the handler when negotiating Expect: 100-continue. An early final response or a redirect that discards the request entity can therefore bypass the handler entirely. Configure request headers before calling this method, rather than inside the handler.

      A handler that writes no bytes can still trigger the HTTP/1.1 handshake when the content length is unknown. An explicit content length of zero bypasses the handshake. A method-preserving redirect received after an upload can invoke the handler again to replay the entity. Account for both bypass and replay when the handler has side effects or consumes a one-shot source.

      Specified by:
      outputStream in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      outputStreamConsumer - handler that writes and closes the request output stream
      Returns:
      response
    • sendExpectContinue

      public T sendExpectContinue(boolean sendExpectContinue)
      Description copied from interface: ClientRequest
      Whether Expect 100-Continue header is sent to verify server availability before sending an entity. Can be used to override the setting inherited from HttpClientConfig.sendExpectContinue() on a per-request basis.
      Specified by:
      sendExpectContinue in interface ClientRequest<T extends ClientRequest<T>>
      Parameters:
      sendExpectContinue - value to override behavior for a single request
      Returns:
      updated client request
    • additionalHeaders

      protected void additionalHeaders()
      Append additional headers before sending the request.
    • method

      public Method method()
      HTTP method to be invoked.
      Specified by:
      method in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      HTTP method
    • properties

      public Map<String,String> properties()
      Properties configured by a user or by other components.
      Specified by:
      properties in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      properties
    • followRedirects

      public boolean followRedirects()
      Description copied from interface: ClientRequest
      Whether to follow redirects.
      Specified by:
      followRedirects in interface ClientRequest<T extends ClientRequest<T>>
      Returns:
      follow redirects
    • maxRedirects

      public int maxRedirects()
      Description copied from interface: ClientRequest
      Maximal number of redirects to follow. This is to prevent infinite redirects.
      Specified by:
      maxRedirects in interface ClientRequest<T extends ClientRequest<T>>
      Returns:
      max number of redirects
    • tls

      public Tls tls()
      Description copied from interface: FullClientRequest
      TLS configuration (may be disabled - e.g. use plaintext).
      Specified by:
      tls in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      TLS configuration
    • sni

      public Optional<SniConfig> sni()
      Description copied from interface: FullClientRequest
      Request-level SNI configuration.
      Specified by:
      sni in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      SNI configuration if configured
    • proxy

      public Proxy proxy()
      Description copied from interface: FullClientRequest
      Proxy configuration (may be no-proxy).
      Specified by:
      proxy in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      proxy
    • selectedProxyRoute

      public Optional<ProxyRoute> selectedProxyRoute()
      Description copied from interface: FullClientRequest
      Effective proxy route already selected during the current top-level request invocation. The route may be shared with protocol fallbacks and other internal handoffs in that invocation.
      Specified by:
      selectedProxyRoute in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      selected proxy route, or empty when this request still needs route selection
    • selectedProxyRoute

      public void selectedProxyRoute(ProxyRoute proxyRoute)
      Description copied from interface: FullClientRequest
      Retain an effective proxy route while handing a request between protocol implementations in the current top-level request invocation. The default implementation validates and otherwise ignores the route.
      Specified by:
      selectedProxyRoute in interface FullClientRequest<T extends ClientRequest<T>>
      Parameters:
      proxyRoute - selected proxy route
    • clearSelectedProxyRoute

      public void clearSelectedProxyRoute()
      Description copied from interface: FullClientRequest
      Clear retained route state after the current top-level request invocation, or when it no longer matches a finalized request target. The default implementation has no effect.
      Specified by:
      clearSelectedProxyRoute in interface FullClientRequest<T extends ClientRequest<T>>
    • connection

      public Optional<ClientConnection> connection()
      Description copied from interface: FullClientRequest
      Possible explicit connection to use (such as when using a proxy).
      Specified by:
      connection in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      client connection if explicitly defined
    • pathParams

      public Map<String,String> pathParams()
      Description copied from interface: FullClientRequest
      Replace a placeholder in URI with an actual value.
      Specified by:
      pathParams in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      a map of path parameters
    • uri

      public ClientUri uri()
      Description copied from interface: FullClientRequest
      URI of this request.
      Specified by:
      uri in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      client URI
    • requestId

      public String requestId()
      Description copied from interface: FullClientRequest
      Request ID.
      Specified by:
      requestId in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      id of this request
    • readTimeout

      public Duration readTimeout()
      Description copied from interface: FullClientRequest
      Read timeout.
      Specified by:
      readTimeout in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      read timeout of this request
    • readContinueTimeout

      public Duration readContinueTimeout()
      Description copied from interface: FullClientRequest
      Read 100-Continue timeout.
      Specified by:
      readContinueTimeout in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      read 100-Continue timeout of this request
    • keepAlive

      public boolean keepAlive()
      Description copied from interface: FullClientRequest
      Whether to use keep-alive connection (if relevant for the used HTTP version).
      Specified by:
      keepAlive in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      whether to use keep alive
    • skipUriEncoding

      public boolean skipUriEncoding()
      Description copied from interface: FullClientRequest
      Whether to skip URI encoding.
      Specified by:
      skipUriEncoding in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      whether to skip encoding
    • sendExpectContinue

      public Optional<Boolean> sendExpectContinue()
      Description copied from interface: FullClientRequest
      Whether Expect 100-Continue header is sent to verify server availability before sending an entity. Overrides the setting from HttpClientConfig.sendExpectContinue().
      Specified by:
      sendExpectContinue in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      Expect 100-Continue value if set
    • address

      public Optional<SocketAddress> address()
      Description copied from interface: FullClientRequest
      Address of the connection, if configured.
      Specified by:
      address in interface FullClientRequest<T extends ClientRequest<T>>
      Returns:
      socket address - may be an InetSocketAddress or UnixDomainSocketAddress
    • doSubmit

      protected abstract R doSubmit(Object entity)
      Submit a request entity.
      Parameters:
      entity - request entity
      Returns:
      HTTP client response
    • doOutputStream

      protected abstract R doOutputStream(ClientRequest.OutputStreamHandler outputStreamHandler)
      Submit a request entity provided through an output stream.
      Parameters:
      outputStreamHandler - output stream handler
      Returns:
      HTTP client response
    • invokeServices

      Invoke configured client services.
      Parameters:
      httpCallChain - invocation of the HTTP request (the actual network call)
      whenSent - completable future to be completed when the request is sent over the network
      whenComplete - completable future to be completed when the request/response interaction finishes
      usedUri - URI configured on the request, combined with the base URI of the client
      Returns:
      web client service response
    • invokeServices

      Invoke configured client services.
      Parameters:
      httpCallChain - invocation of the HTTP request (the actual network call)
      whenSent - completable future to be completed when the request is sent over the network
      whenComplete - completable future to be completed when the request/response interaction finishes
      usedUri - URI configured on the request, combined with the base URI of the client
      Returns:
      web client service response
    • invokeServices

      Invoke configured client services and publish applicable transport response context before they unwind.
      Parameters:
      webClient - client that owns the transport protocols
      httpCallChain - invocation of the HTTP request (the actual network call)
      whenSent - completable future to be completed when the request is sent over the network
      whenComplete - completable future to be completed when the request/response interaction finishes
      usedUri - URI configured on the request, combined with the base URI of the client
      Returns:
      web client service response
    • clientConfig

      protected HttpClientConfig clientConfig()
      Associated client configuration.
      Returns:
      client config
    • sanitizeRedirectSensitiveHeaders

      protected final void sanitizeRedirectSensitiveHeaders(ClientUri requestUri, ClientRequestHeaders requestHeaders)
      Remove headers that must not cross redirect trust boundaries.
      Parameters:
      requestUri - URI that will be used for the request
      requestHeaders - headers to sanitize
    • crossesRedirectOriginBoundary

      protected final boolean crossesRedirectOriginBoundary(ClientUri requestUri)
      Whether a redirect from this request to the provided URI would cross, or has already crossed, an origin boundary.
      Parameters:
      requestUri - redirect request URI
      Returns:
      whether redirect-sensitive headers should be stripped
    • mediaContext

      protected MediaContext mediaContext()
      Media context configured for this request.
      Returns:
      media context
    • resolveUri

      protected ClientUri resolveUri(ClientUri toResolve)
      Resolve possible templated URI definition against the provided ClientUri, extracting possible query information into the provided writable query.
      Parameters:
      toResolve - client uri to update from the template
      Returns:
      updated client uri
    • resolveRedirectUri

      protected final ClientUri resolveRedirectUri(String location)
      Resolve a redirect target's scheme and authority against this request.
      Parameters:
      location - Location header value
      Returns:
      resolved redirect URI