Interface HTTPClient

All Superinterfaces:
AutoCloseable, Closeable

public interface HTTPClient extends Closeable
A HTTPClient is associated with a single connection to a server where requests can be sent to using newRequest(HTTPRequest).

The application must call receive(byte[]) when receiving data on the connection to the server.

Since:
1.4.1
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Terminates this HTTPClient at any time, causing the connection to be terminated.
    Returns a (possibly unmodifiable) collection of all currently active request transactions managed by this HTTPClient.
    Returns the connection to the server.
    int
    Returns the maximum number of concurrent active requests this HTTPClient can be used for.
    Creates a new HTTPClientStream for the given request.
    void
    receive(byte[] data)
    Called by the application when it receives data from the server connection this HTTPClient is associated with.
    default void
    setServerPushEnabled(boolean enabled)
    Enables or disabled server push.
  • Method Details

    • receive

      void receive(byte[] data) throws HTTPException
      Called by the application when it receives data from the server connection this HTTPClient is associated with.
      Parameters:
      data - The data
      Throws:
      HTTPException - If the given data could not be successfully processed or is otherwise malformed
    • getConnection

      WritableSocket getConnection()
      Returns the connection to the server.
      Returns:
      The connection
    • close

      void close()
      Terminates this HTTPClient at any time, causing the connection to be terminated.

      Calling this method also closes all active requests.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • setServerPushEnabled

      default void setServerPushEnabled(boolean enabled)
      Enables or disabled server push.

      If server push is not supported by the underlying protocol, this setting has no effect.

      Parameters:
      enabled - true to enable server push
    • newRequest

      HTTPClientStream newRequest(HTTPRequest request)
      Creates a new HTTPClientStream for the given request.

      It is possible that this HTTPClient cannot create a new request stream. In this case, null is returned.

      Returns:
      The HTTPClientStream, or null if no new request can be sent
      Throws:
      IllegalStateException - If this HTTPClient is closed (optional)
      See Also:
    • getActiveRequests

      Collection<HTTPClientStream> getActiveRequests()
      Returns a (possibly unmodifiable) collection of all currently active request transactions managed by this HTTPClient. This is the set of all HTTPClientStreams which have not received a complete response yet.
      Returns:
      The collection of active HTTPClientStreams
    • getMaxConcurrentRequestCount

      int getMaxConcurrentRequestCount()
      Returns the maximum number of concurrent active requests this HTTPClient can be used for.
      Returns:
      The maximum number of concurrent requests