Interface HttpClientSpi

All Superinterfaces:
ReleasableResource
All Known Implementing Classes:
Http2ClientImpl

public interface HttpClientSpi extends ReleasableResource
Integration for HTTP versions to provide a single API.
  • Method Details

    • supports

      HttpClientSpi.SupportLevel supports(FullClientRequest<?> clientRequest, ClientUri clientUri)
      Return whether this HTTP version can handle the provided request.

      Examples:

      • HTTP/1.1 always returns true, as it is the fallback protocol of all other protocols
      • HTTP/2 returns true when upgrade is enabled, false when prior-knowledge is specified (as we can always attempt to upgrade and fallback to 1.1 in the first case, but we would fail with prior-knowledge, unless the endpoint is known to be HTTP/2
      • HTTP/3 would always return true, as it cannot fallback once a connection is attempted
      So how can we get to HTTP/2 with prior knowledge, or HTTP/3? There are the following options:
      • An explicit protocol id is configured for the request - HttpClientRequest.protocolId(String)
      • There is no fallback protocol enabled, in such a case, we use the one with highest priority - see WebClientConfig.BuilderBase.addProtocolPreference(String)
      • We get an Alt-Svc header from a response that points us to a protocol version (we only support permanent protocol changes, Alt-Svc with timeout will be ignored
      • This protocol version already handled a request to such an endpoint and has the connection available
      Note that this response is cached.
      Parameters:
      clientRequest - HTTP request
      clientUri - URI to invoke
      Returns:
      true if we are sure we can handle this request with this protocol version
    • clientRequest

      ClientRequest<?> clientRequest(FullClientRequest<?> clientRequest, ClientUri clientUri)
      Create a client request based on the provided HTTP request that is for the version of this client.
      Parameters:
      clientRequest - request configuration
      clientUri - URI to invoke (resolved)
      Returns:
      a new request
    • isTcp

      default boolean isTcp()
      For TCP based protocols, we can do ALPN negotiation, obtain a connection, and then let the client handle the protocol. Similar for proxies - we can establish a proxy connection, and then let the client handle the protocol. For UDP based protocols, we need to wait for Alt-Svc headers before attempting anything, or have an explicit version configured.
      Returns:
      whether this is a TCP based HTTP protocol, defaults to true