- java.lang.Object
-
- org.eclipse.jetty.io.AbstractConnection
-
- org.eclipse.jetty.server.HttpConnection
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Runnable,Connection,Connection.UpgradeFrom,Connection.UpgradeTo,WriteFlusher.Listener,HttpTransport
public class HttpConnection extends AbstractConnection implements java.lang.Runnable, HttpTransport, WriteFlusher.Listener, Connection.UpgradeFrom, Connection.UpgradeTo
A
Connectionthat 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 Modifier and Type Field Description static HttpFieldCONNECTION_CLOSE-
Fields inherited from interface org.eclipse.jetty.server.HttpTransport
UPGRADE_CONNECTION_ATTRIBUTE
-
-
Constructor Summary
Constructors Constructor Description HttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint, boolean recordComplianceViolations)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort(java.lang.Throwable failure)Aborts this transport.voidasyncReadFillInterested()voidblockingReadFailure(java.lang.Throwable e)voidblockingReadFillInterested()protected booleanfillAndParseForContent()Fill and parse data looking for contentlonggetBytesIn()longgetBytesOut()ConnectorgetConnector()static HttpConnectiongetCurrentConnection()Get the current connection that this thread is dispatched to.HttpGeneratorgetGenerator()HttpChannelgetHttpChannel()HttpConfigurationgetHttpConfiguration()longgetMessagesIn()longgetMessagesOut()HttpParsergetParser()java.nio.ByteBuffergetRequestBuffer()ServergetServer()booleanisPushSupported()booleanisRecordHttpComplianceViolations()booleanisRequestBufferEmpty()booleanisUseInputDirectByteBuffers()booleanisUseOutputDirectByteBuffers()protected HttpChannelOverHttpnewHttpChannel()protected HttpGeneratornewHttpGenerator()protected HttpParsernewHttpParser(HttpCompliance compliance)protected HttpParser.RequestHandlernewRequestHandler()voidonClose(java.lang.Throwable cause)Callback method invoked when this connection is closed.voidonCompleted()Called to indicated the end of the current request/response cycle (which may be some time after the last content is sent).voidonFillable()Callback method invoked when the endpoint is ready to be read.protected voidonFillInterestedFailed(java.lang.Throwable cause)Callback method invoked when the endpoint failed to be ready to be read.voidonFlushed(long bytes)Invoked when aWriteFlusherflushed bytes in a non-blocking way, as part of a - possibly larger - write.voidonOpen()Callback method invoked when this connection is opened.protected booleanonReadTimeout(java.lang.Throwable timeout)Callback method invoked when the endpoint failed to be ready to be read after a timeoutjava.nio.ByteBufferonUpgradeFrom()Takes the input buffer from the connection on upgrade.voidonUpgradeTo(java.nio.ByteBuffer buffer)Callback method invoked when this connection is upgraded.voidpush(MetaData.Request request)voidrun()voidsend(MetaData.Request request, MetaData.Response response, java.nio.ByteBuffer content, boolean lastContent, Callback callback)Asynchronous call to send a response (or part) over the transportprotected static HttpConnectionsetCurrentConnection(HttpConnection connection)voidsetUseInputDirectByteBuffers(boolean useInputDirectByteBuffers)voidsetUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers)java.lang.StringtoConnectionString()-
Methods inherited from class org.eclipse.jetty.io.AbstractConnection
addEventListener, close, failedCallback, fillInterested, getCreatedTimeStamp, getEndPoint, getExecutor, getInputBufferSize, isFillInterested, onIdleExpired, removeEventListener, setInputBufferSize, toString, tryFillInterested, tryFillInterested
-
-
-
-
Field Detail
-
CONNECTION_CLOSE
public static final HttpField CONNECTION_CLOSE
-
-
Constructor Detail
-
HttpConnection
public HttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint, boolean recordComplianceViolations)
-
-
Method Detail
-
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:
for a more general way to access the HttpConnection
-
setCurrentConnection
protected static HttpConnection setCurrentConnection(HttpConnection connection)
-
getHttpConfiguration
public HttpConfiguration getHttpConfiguration()
-
isRecordHttpComplianceViolations
public boolean isRecordHttpComplianceViolations()
-
newHttpGenerator
protected HttpGenerator newHttpGenerator()
-
newHttpChannel
protected HttpChannelOverHttp newHttpChannel()
-
newHttpParser
protected HttpParser newHttpParser(HttpCompliance compliance)
-
newRequestHandler
protected HttpParser.RequestHandler newRequestHandler()
-
getServer
public Server getServer()
-
getConnector
public Connector getConnector()
-
getHttpChannel
public HttpChannel getHttpChannel()
-
getParser
public HttpParser getParser()
-
getGenerator
public HttpGenerator getGenerator()
-
getMessagesIn
public long getMessagesIn()
- Specified by:
getMessagesInin interfaceConnection- Overrides:
getMessagesInin classAbstractConnection
-
getMessagesOut
public long getMessagesOut()
- Specified by:
getMessagesOutin interfaceConnection- Overrides:
getMessagesOutin classAbstractConnection
-
isUseInputDirectByteBuffers
public boolean isUseInputDirectByteBuffers()
-
setUseInputDirectByteBuffers
public void setUseInputDirectByteBuffers(boolean useInputDirectByteBuffers)
-
isUseOutputDirectByteBuffers
public boolean isUseOutputDirectByteBuffers()
-
setUseOutputDirectByteBuffers
public void setUseOutputDirectByteBuffers(boolean useOutputDirectByteBuffers)
-
onUpgradeFrom
public java.nio.ByteBuffer onUpgradeFrom()
Description copied from interface:Connection.UpgradeFromTakes the input buffer from the connection on upgrade.
This method is used to take any unconsumed input from a connection during an upgrade.
- Specified by:
onUpgradeFromin interfaceConnection.UpgradeFrom- Returns:
- A buffer of unconsumed input. The caller must return the buffer to the bufferpool when consumed and this connection must not.
-
onUpgradeTo
public void onUpgradeTo(java.nio.ByteBuffer buffer)
Description copied from interface:Connection.UpgradeToCallback method invoked when this connection is upgraded.
This must be called before
Connection.onOpen().- Specified by:
onUpgradeToin interfaceConnection.UpgradeTo- Parameters:
buffer- An optional buffer that can contain prefilled data. Typically this results from an upgrade of one protocol to the other where the old connection has buffered data destined for the new connection. The new connection must take ownership of the buffer and is responsible for returning it to the buffer pool
-
onFlushed
public void onFlushed(long bytes) throws java.io.IOExceptionDescription copied from interface:WriteFlusher.ListenerInvoked when a
WriteFlusherflushed 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
IOExceptionto signal that the write should fail, for example if the implementation enforces a minimum data rate.- Specified by:
onFlushedin interfaceWriteFlusher.Listener- Parameters:
bytes- the number of bytes flushed- Throws:
java.io.IOException- if the write should fail
-
getRequestBuffer
public java.nio.ByteBuffer getRequestBuffer()
-
isRequestBufferEmpty
public boolean isRequestBufferEmpty()
-
onFillable
public void onFillable()
Description copied from class:AbstractConnectionCallback method invoked when the endpoint is ready to be read.
- Specified by:
onFillablein classAbstractConnection- See Also:
AbstractConnection.fillInterested()
-
fillAndParseForContent
protected boolean fillAndParseForContent()
Fill and parse data looking for content- Returns:
- true if an
HttpParser.RequestHandlermethod was called and it returned true;
-
onCompleted
public void onCompleted()
Description copied from interface:HttpTransportCalled to indicated the end of the current request/response cycle (which may be some time after the last content is sent).- Specified by:
onCompletedin interfaceHttpTransport
-
onReadTimeout
protected boolean onReadTimeout(java.lang.Throwable timeout)
Description copied from class:AbstractConnectionCallback method invoked when the endpoint failed to be ready to be read after a timeout
- Overrides:
onReadTimeoutin 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
protected void onFillInterestedFailed(java.lang.Throwable cause)
Description copied from class:AbstractConnectionCallback method invoked when the endpoint failed to be ready to be read.
- Overrides:
onFillInterestedFailedin classAbstractConnection- Parameters:
cause- the exception that caused the failure
-
onOpen
public void onOpen()
Description copied from interface:ConnectionCallback method invoked when this connection is opened.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onOpenin interfaceConnection- Overrides:
onOpenin classAbstractConnection
-
onClose
public void onClose(java.lang.Throwable cause)
Description copied from interface:ConnectionCallback method invoked when this connection is closed.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onClosein interfaceConnection- Overrides:
onClosein classAbstractConnection- Parameters:
cause- The cause of the close or null for a normal close
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
send
public void send(MetaData.Request request, MetaData.Response response, java.nio.ByteBuffer content, boolean lastContent, Callback callback)
Description copied from interface:HttpTransportAsynchronous call to send a response (or part) over the transport- Specified by:
sendin 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
public void abort(java.lang.Throwable failure)
Description copied from interface:HttpTransportAborts 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:
abortin interfaceHttpTransport- Parameters:
failure- the failure that caused the abort.
-
isPushSupported
public boolean isPushSupported()
- Specified by:
isPushSupportedin interfaceHttpTransport- Returns:
- true if responses can be pushed over this transport
-
push
public void push(MetaData.Request request)
- Specified by:
pushin interfaceHttpTransport- Parameters:
request- A request to use as the basis for generating a pushed response.
-
asyncReadFillInterested
public void asyncReadFillInterested()
-
blockingReadFillInterested
public void blockingReadFillInterested()
-
blockingReadFailure
public void blockingReadFailure(java.lang.Throwable e)
-
getBytesIn
public long getBytesIn()
- Specified by:
getBytesInin interfaceConnection- Overrides:
getBytesInin classAbstractConnection
-
getBytesOut
public long getBytesOut()
- Specified by:
getBytesOutin interfaceConnection- Overrides:
getBytesOutin classAbstractConnection
-
toConnectionString
public java.lang.String toConnectionString()
- Overrides:
toConnectionStringin classAbstractConnection
-
-