Class HttpConnection

All Implemented Interfaces:
Closeable, AutoCloseable, Runnable, Connection, Connection.UpgradeFrom, Connection.UpgradeTo, WriteFlusher.Listener, ConnectionMetaData, Attributes, Invocable

A Connection that handles the HTTP protocol.

  • Constructor Details

  • Method Details

    • getCurrentConnection

      public static HttpConnection getCurrentConnection()
      Get the current connection that this thread is dispatched to. Note that a thread may be processing a request asynchronously and thus not be dispatched to the connection.
      Returns:
      the current HttpConnection or null
      See Also:
    • setCurrentConnection

      protected static HttpConnection setCurrentConnection(HttpConnection connection)
    • getInvocationType

      public Invocable.InvocationType getInvocationType()
      Specified by:
      getInvocationType in interface Invocable
      Overrides:
      getInvocationType in class AbstractConnection
      Returns:
      The InvocationType of this object
    • isRecordHttpComplianceViolations

      @Deprecated(since="12.0.6", forRemoval=true) public boolean isRecordHttpComplianceViolations()
      Deprecated, for removal: This API element is subject to removal in a future version.
      No replacement, no longer used within HttpConnection, will be removed in Jetty 12.1.0
    • newHttpGenerator

      protected HttpGenerator newHttpGenerator()
    • newHttpParser

      protected HttpParser newHttpParser(HttpCompliance compliance)
    • newHttpChannel

      protected HttpChannel newHttpChannel(Server server, HttpConfiguration configuration)
    • newHttpStream

      protected HttpConnection.HttpStreamOverHTTP1 newHttpStream(String method, String uri, HttpVersion version)
    • newRequestHandler

      protected HttpConnection.RequestHandler newRequestHandler()
    • getServer

      public Server getServer()
    • getHttpChannel

      public HttpChannel getHttpChannel()
    • getParser

      public HttpParser getParser()
    • getGenerator

      public HttpGenerator getGenerator()
    • getId

      public String getId()
      Specified by:
      getId in interface ConnectionMetaData
      Returns:
      a unique (within the lifetime of the JVM) identifier string for the network connection to the JVM
    • getHttpVersion

      public HttpVersion getHttpVersion()
      Specified by:
      getHttpVersion in interface ConnectionMetaData
    • getProtocol

      public String getProtocol()
      Specified by:
      getProtocol in interface ConnectionMetaData
    • isPersistent

      public boolean isPersistent()
      Specified by:
      isPersistent in interface ConnectionMetaData
    • removeAttribute

      public Object removeAttribute(String name)
      Description copied from interface: Attributes
      Remove an attribute
      Specified by:
      removeAttribute in interface Attributes
      Parameters:
      name - the attribute to remove
      Returns:
      the value of the attribute if removed, else null
    • setAttribute

      public Object setAttribute(String name, Object attribute)
      Description copied from interface: Attributes
      Set an attribute
      Specified by:
      setAttribute in interface Attributes
      Parameters:
      name - the attribute to set
      attribute - the value to set. A null value is equivalent to removing the attribute.
      Returns:
      the previous value of the attribute if set, else null
    • getAttribute

      public Object getAttribute(String name)
      Description copied from interface: Attributes
      Get an attribute
      Specified by:
      getAttribute in interface Attributes
      Parameters:
      name - the attribute to get
      Returns:
      the value of the attribute
    • getAttributeNameSet

      public Set<String> getAttributeNameSet()
      Description copied from interface: Attributes
      Get the immutable set of attribute names.
      Specified by:
      getAttributeNameSet in interface Attributes
      Returns:
      Set of attribute names
    • clearAttributes

      public void clearAttributes()
      Description copied from interface: Attributes
      Clear all attribute names
      Specified by:
      clearAttributes in interface Attributes
    • getMessagesIn

      public long getMessagesIn()
      Specified by:
      getMessagesIn in interface Connection
      Overrides:
      getMessagesIn in class AbstractConnection
    • getMessagesOut

      public long getMessagesOut()
      Specified by:
      getMessagesOut in interface Connection
      Overrides:
      getMessagesOut in class AbstractConnection
    • isUseInputDirectByteBuffers

      public boolean isUseInputDirectByteBuffers()
    • setUseInputDirectByteBuffers

      public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers)
    • isUseOutputDirectByteBuffers

      public boolean isUseOutputDirectByteBuffers()
    • setUseOutputDirectByteBuffers

      public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers)
    • onUpgradeFrom

      public ByteBuffer onUpgradeFrom()
      Description copied from interface: Connection.UpgradeFrom

      Invoked during an upgrade to produce a buffer containing bytes that have not been consumed by this connection, and that must be consumed by the upgrade-to connection.

      Specified by:
      onUpgradeFrom in interface Connection.UpgradeFrom
      Returns:
      a buffer of unconsumed bytes to pass to the upgrade-to connection. The buffer does not belong to any pool and should be discarded after having consumed its bytes. The returned buffer may be null if there are no unconsumed bytes.
    • onUpgradeTo

      public void onUpgradeTo(ByteBuffer buffer)
      Description copied from interface: Connection.UpgradeTo

      Invoked during an upgrade to receive a buffer containing bytes that have not been consumed by the upgrade-from connection, and that must be consumed by this connection.

      Specified by:
      onUpgradeTo in interface Connection.UpgradeTo
      Parameters:
      buffer - a non-null buffer of unconsumed bytes received from the upgrade-from connection. The buffer does not belong to any pool and should be discarded after having consumed its bytes.
    • onFlushed

      public void onFlushed(long bytes) throws IOException
      Description copied from interface: WriteFlusher.Listener

      Invoked when a WriteFlusher flushed bytes in a non-blocking way, as part of a - possibly larger - write.

      This method may be invoked multiple times, for example when writing a large buffer: a first flush of bytes, then the connection became TCP congested, and a subsequent flush of bytes when the connection became writable again.

      This method is never invoked concurrently, but may be invoked by different threads, so implementations may not rely on thread-local variables.

      Implementations may throw an IOException to signal that the write should fail, for example if the implementation enforces a minimum data rate.

      Specified by:
      onFlushed in interface WriteFlusher.Listener
      Parameters:
      bytes - the number of bytes flushed
      Throws:
      IOException - if the write should fail
    • isRequestBufferEmpty

      public boolean isRequestBufferEmpty()
    • onFillable

      public void onFillable()
      Description copied from class: AbstractConnection

      Callback method invoked when the endpoint is ready to be read.

      Specified by:
      onFillable in class AbstractConnection
      See Also:
    • onFillInterestedFailed

      protected void onFillInterestedFailed(Throwable cause)
      Description copied from class: AbstractConnection

      Callback method invoked when the endpoint failed to be ready to be read.

      Overrides:
      onFillInterestedFailed in class AbstractConnection
      Parameters:
      cause - the exception that caused the failure
    • onIdleExpired

      public boolean onIdleExpired(TimeoutException timeout)
      Description copied from interface: Connection

      Callback method invoked upon an idle timeout event.

      Implementations of this method may return true to indicate that the idle timeout handling should proceed normally, typically failing the EndPoint and causing it to be closed.

      When false is returned, the handling of the idle timeout event is halted immediately and the EndPoint left in the state it was before the idle timeout event.

      Specified by:
      onIdleExpired in interface Connection
      Overrides:
      onIdleExpired in class AbstractConnection
      Returns:
      true to let the EndPoint handle the idle timeout, false to tell the EndPoint to halt the handling of the idle timeout.
    • close

      public void close()
      Description copied from interface: Connection

      Performs a logical close of this connection.

      For simple connections, this may just mean to delegate the close to the associated EndPoint but, for example, SSL connections should write the SSL close message before closing the associated EndPoint.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Connection
      Overrides:
      close in class AbstractConnection
    • onOpen

      public void onOpen()
      Description copied from interface: Connection

      Callback method invoked when this connection is opened.

      Creators of the connection implementation are responsible for calling this method.

      Specified by:
      onOpen in interface Connection
      Overrides:
      onOpen in class AbstractConnection
    • onClose

      public void onClose(Throwable cause)
      Description copied from interface: Connection

      Callback method invoked when this connection is closed.

      Creators of the connection implementation are responsible for calling this method.

      Specified by:
      onClose in interface Connection
      Overrides:
      onClose in class AbstractConnection
      Parameters:
      cause - The cause of the close or null for a normal close
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • asyncReadFillInterested

      public void asyncReadFillInterested()
    • getBytesIn

      public long getBytesIn()
      Specified by:
      getBytesIn in interface Connection
      Overrides:
      getBytesIn in class AbstractConnection
    • getBytesOut

      public long getBytesOut()
      Specified by:
      getBytesOut in interface Connection
      Overrides:
      getBytesOut in class AbstractConnection
    • toConnectionString

      public String toConnectionString()
      Overrides:
      toConnectionString in class AbstractConnection