Class HttpConnection
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Runnable
,Connection
,Connection.UpgradeFrom
,Connection.UpgradeTo
,WriteFlusher.Listener
,HttpTransport
A Connection
that handles the HTTP protocol.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Connection
Connection.Listener, Connection.UpgradeFrom, Connection.UpgradeTo
-
Field Summary
Fields inherited from interface org.eclipse.jetty.server.HttpTransport
UPGRADE_CONNECTION_ATTRIBUTE
-
Constructor Summary
ConstructorDescriptionHttpConnection
(HttpConfiguration config, Connector connector, EndPoint endPoint, boolean recordComplianceViolations) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Aborts this transport.void
long
long
long
static HttpConnection
Get the current connection that this thread is dispatched to.long
long
boolean
boolean
boolean
boolean
boolean
protected HttpChannelOverHttp
protected HttpGenerator
protected HttpParser
newHttpParser
(HttpCompliance compliance) protected HttpParser.RequestHandler
void
Callback method invoked when this connection is closed.void
Called to indicated the end of the current request/response cycle (which may be some time after the last content is sent).void
Callback method invoked when the endpoint is ready to be read.protected void
onFillInterestedFailed
(Throwable cause) Callback method invoked when the endpoint failed to be ready to be read.void
onFlushed
(long bytes) Invoked when aWriteFlusher
flushed bytes in a non-blocking way, as part of a - possibly larger - write.void
onOpen()
Callback method invoked when this connection is opened.protected boolean
onReadTimeout
(Throwable timeout) Callback method invoked when the endpoint failed to be ready to be read after a timeoutInvoked during anupgrade
to produce a buffer containing bytes that have not been consumed by this connection, and that must be consumed by the upgrade-to connection.void
onUpgradeTo
(ByteBuffer buffer) Invoked during anupgrade
to receive a buffer containing bytes that have not been consumed by the upgrade-from connection, and that must be consumed by this connection.void
push
(MetaData.Request request) void
run()
void
send
(MetaData.Request request, MetaData.Response response, ByteBuffer content, boolean lastContent, Callback callback) Asynchronous call to send a response (or part) over the transportprotected static HttpConnection
setCurrentConnection
(HttpConnection connection) void
setUseInputDirectByteBuffers
(boolean useInputDirectByteBuffers) void
setUseOutputDirectByteBuffers
(boolean useOutputDirectByteBuffers) Methods inherited from class org.eclipse.jetty.io.AbstractConnection
addEventListener, close, failedCallback, fillInterested, getCreatedTimeStamp, getEndPoint, getExecutor, getInputBufferSize, isFillInterested, onIdleExpired, removeEventListener, setInputBufferSize, toString, tryFillInterested
-
Field Details
-
CONNECTION_CLOSE
-
-
Constructor Details
-
HttpConnection
public HttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint, boolean recordComplianceViolations)
-
-
Method Details
-
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
-
getBeginNanoTime
public long getBeginNanoTime() -
getHttpConfiguration
-
isRecordHttpComplianceViolations
public boolean isRecordHttpComplianceViolations() -
newHttpGenerator
-
newHttpChannel
-
newHttpParser
-
newRequestHandler
-
getServer
-
getConnector
-
getHttpChannel
-
getParser
-
getGenerator
-
getMessagesIn
public long getMessagesIn()- Specified by:
getMessagesIn
in interfaceConnection
- Overrides:
getMessagesIn
in classAbstractConnection
-
getMessagesOut
public long getMessagesOut()- Specified by:
getMessagesOut
in interfaceConnection
- Overrides:
getMessagesOut
in classAbstractConnection
-
isUseInputDirectByteBuffers
public boolean isUseInputDirectByteBuffers() -
setUseInputDirectByteBuffers
public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers) -
isUseOutputDirectByteBuffers
public boolean isUseOutputDirectByteBuffers() -
setUseOutputDirectByteBuffers
public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers) -
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 interfaceConnection.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
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 interfaceConnection.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
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 interfaceWriteFlusher.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 classAbstractConnection
- See Also:
-
onCompleted
public void onCompleted()Description copied from interface:HttpTransport
Called to indicated the end of the current request/response cycle (which may be some time after the last content is sent).- Specified by:
onCompleted
in interfaceHttpTransport
-
onReadTimeout
Description copied from class:AbstractConnection
Callback method invoked when the endpoint failed to be ready to be read after a timeout
- Overrides:
onReadTimeout
in classAbstractConnection
- Parameters:
timeout
- the cause of the read timeout- Returns:
- true to signal that the endpoint must be closed, false to keep the endpoint open
-
onFillInterestedFailed
Description copied from class:AbstractConnection
Callback method invoked when the endpoint failed to be ready to be read.
- Overrides:
onFillInterestedFailed
in classAbstractConnection
- Parameters:
cause
- the exception that caused the failure
-
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 interfaceConnection
- Overrides:
onOpen
in classAbstractConnection
-
onClose
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 interfaceConnection
- Overrides:
onClose
in classAbstractConnection
- Parameters:
cause
- The cause of the close or null for a normal close
-
run
public void run() -
send
public void send(MetaData.Request request, MetaData.Response response, ByteBuffer content, boolean lastContent, Callback callback) Description copied from interface:HttpTransport
Asynchronous call to send a response (or part) over the transport- Specified by:
send
in interfaceHttpTransport
- Parameters:
request
- True if the response if for a HEAD request (and the data should not be sent).response
- The header info to send, or null if just sending more data. The first call to send for a response must have a non null info.content
- A buffer of content to be sent.lastContent
- True if the content is the last content for the current response.callback
- The Callback instance that success or failure of the send is notified on
-
abort
Description copied from interface:HttpTransport
Aborts this transport.This method should terminate the transport in a way that can indicate an abnormal response to the client, for example by abruptly close the connection.
This method is called when an error response needs to be sent, but the response is already committed, or when a write failure is detected. If abort is called,
HttpTransport.onCompleted()
is not called- Specified by:
abort
in interfaceHttpTransport
- Parameters:
failure
- the failure that caused the abort.
-
isPushSupported
public boolean isPushSupported()- Specified by:
isPushSupported
in interfaceHttpTransport
- Returns:
- true if responses can be pushed over this transport
-
push
- Specified by:
push
in interfaceHttpTransport
- Parameters:
request
- A request to use as the basis for generating a pushed response.
-
asyncReadFillInterested
public void asyncReadFillInterested() -
getBytesIn
public long getBytesIn()- Specified by:
getBytesIn
in interfaceConnection
- Overrides:
getBytesIn
in classAbstractConnection
-
getBytesOut
public long getBytesOut()- Specified by:
getBytesOut
in interfaceConnection
- Overrides:
getBytesOut
in classAbstractConnection
-
toConnectionString
- Overrides:
toConnectionString
in classAbstractConnection
-