Interface HttpChannel

All Superinterfaces:
Invocable
All Known Implementing Classes:
HttpChannelState

public interface HttpChannel extends Invocable

Represents the state of an HTTP request/response cycle.

HttpChannel links the lower (closer to the network) layer HttpStream with the upper (application code) layer Handler.

An HttpChannel instance may be used for many HTTP request/response cycles from the same connection; however, only a single cycle may be active at any time.

Default implementations of this interface may be created via HttpChannel.DefaultFactory.

  • Method Details

    • getConnectionMetaData

      ConnectionMetaData getConnectionMetaData()
      Returns:
      the ConnectionMetaData associated with this channel.
    • setHttpStream

      void setHttpStream(HttpStream httpStream)
      Set the HttpStream to associate to this channel..
      Parameters:
      httpStream - the HttpStream to associate to this channel.
    • isRequestHandled

      boolean isRequestHandled()
      Returns:
      whether the request has been passed to the root Handler.
    • onRequest

      Runnable onRequest(MetaData.Request metaData)

      HttpStream invokes this method when the metadata of an HTTP request (method, URI and headers, but not content) has been parsed.

      The returned Runnable invokes the root Handler.

      Parameters:
      metaData - the HTTP request metadata.
      Returns:
      a Runnable that invokes the root Handler.
    • getRequest

      Request getRequest()

      Returns the Request object, if available.

      The Request object is only available after a call to onRequest(MetaData.Request) has been made.

      Returns:
      the Request object, or null if the Request object is not yet available.
    • onContentAvailable

      Runnable onContentAvailable()

      HttpStream invokes this method when more HTTP request content is available.

      Returns:
      the last Runnable passed to Request.demand(Runnable), or null if there is no demand for content.
    • onIdleTimeout

      Runnable onIdleTimeout(TimeoutException idleTimeout)

      Notifies this HttpChannel that an idle timeout happened.

      Parameters:
      idleTimeout - the timeout.
      Returns:
      a Runnable that performs the timeout action, or null if no action need be performed by the calling thread
      See Also:
    • onFailure

      Runnable onFailure(Throwable failure)

      Notifies this HttpChannel that an asynchronous failure happened.

      Typical failure examples could be HTTP/2 resets or protocol failures (for example, invalid request bytes).

      Parameters:
      failure - the failure cause.
      Returns:
      a Runnable that performs the failure action, or null if no failure action need be performed by the calling thread
      See Also:
    • recycle

      void recycle()
      Recycle the HttpChannel, so that a new cycle of calling setHttpStream(HttpStream), onRequest(MetaData.Request) etc. may be performed on the channel.
      See Also:
    • initialize

      void initialize()
      Initialize the HttpChannel when a new cycle of request handling begins.
      See Also:
    • getComplianceViolationListener

      ComplianceViolation.Listener getComplianceViolationListener()
      Returns:
      the active ComplianceViolation.Listener
    • from

      static HttpChannel from(Request request)
      Parameters:
      request - attempt to resolve the HttpChannel from the provided request
      Returns:
      the HttpChannel if found
      Throws:
      IllegalStateException - if unable to find HttpChannel