Module bus.http

Class RealConnection

All Implemented Interfaces:
Connection

public final class RealConnection extends Http2Connection.Listener implements Connection
A concrete connection to a target server (either directly or via a proxy). This class handles the low-level details of establishing and maintaining the connection, including TLS handshakes and HTTP/2 multiplexing.
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

  • Constructor Details

  • Method Details

    • noNewExchanges

      public void noNewExchanges()
      Prevents further exchanges from being created on this connection.
    • connect

      public void connect(int connectTimeout, int readTimeout, int writeTimeout, int pingIntervalMillis, boolean connectionRetryEnabled, NewCall call, EventListener eventListener) throws IOException
      Establishes a connection to the target server.
      Parameters:
      connectTimeout - The connect timeout in milliseconds.
      readTimeout - The read timeout in milliseconds.
      writeTimeout - The write timeout in milliseconds.
      pingIntervalMillis - The ping interval in milliseconds for HTTP/2.
      connectionRetryEnabled - Whether connection retries are enabled.
      call - The call that initiated this connection.
      eventListener - The event listener for connection events.
      Throws:
      IOException - if an I/O error occurs during connection establishment.
    • supportsUrl

      public boolean supportsUrl(UnoUrl url)
      Returns true if this connection can be used for url.
      Parameters:
      url - The URL to check.
      Returns:
      true if the connection supports the URL.
    • route

      public Route route()
      Description copied from interface: Connection
      Returns the route that this connection follows.
      Specified by:
      route in interface Connection
      Returns:
      The route of this connection.
    • cancel

      public void cancel()
      Cancels this connection.
    • socket

      public Socket socket()
      Description copied from interface: Connection
      Returns the socket that this connection uses. If this connection is HTTPS, this is an SSLSocket. If this is an HTTP/2 connection the socket may be shared by multiple concurrent calls.
      Specified by:
      socket in interface Connection
      Returns:
      The socket for this connection.
    • isHealthy

      public boolean isHealthy(boolean doExtensiveChecks)
      Returns true if this connection is ready to host new streams.
      Parameters:
      doExtensiveChecks - Whether to perform extensive health checks.
      Returns:
      true if the connection is healthy.
    • onStream

      public void onStream(Http2Stream stream) throws IOException
      Refuses incoming streams.
      Specified by:
      onStream in class Http2Connection.Listener
      Parameters:
      stream - The HTTP/2 stream.
      Throws:
      IOException - if an I/O error occurs.
    • onSettings

      public void onSettings(Http2Connection connection)
      When settings are received, adjust the allocation limit.
      Overrides:
      onSettings in class Http2Connection.Listener
      Parameters:
      connection - The HTTP/2 connection.
    • handshake

      public Handshake handshake()
      Description copied from interface: Connection
      Returns the TLS handshake used to establish this connection, or null if the connection is not HTTPS.
      Specified by:
      handshake in interface Connection
      Returns:
      The TLS handshake, or null.
    • isMultiplexed

      public boolean isMultiplexed()
      Returns true if this is an HTTP/2 connection. Such connections can be used in multiple HTTP requests simultaneously.
      Returns:
      true if the connection is multiplexed.
    • protocol

      public org.miaixz.bus.core.net.Protocol protocol()
      Description copied from interface: Connection
      Returns the protocol negotiated by this connection, or Protocol.HTTP_1_1 if no protocol was negotiated. This method returns Protocol.HTTP_1_1 even if the remote peer is using Protocol.HTTP_1_0.
      Specified by:
      protocol in interface Connection
      Returns:
      The negotiated protocol.
    • toString

      public String toString()
      Overrides:
      toString in class Object