public class HttpConnection extends AbstractConnection implements java.lang.Runnable, HttpTransport, Connection.UpgradeFrom, WriteFlusher.Listener
A Connection that handles the HTTP protocol.
| Modifier and Type | Class and Description |
|---|---|
private class |
HttpConnection.AsyncReadCallback |
private class |
HttpConnection.BlockingReadCallback |
private class |
HttpConnection.Content |
private class |
HttpConnection.SendCallback |
Connection.Listener, Connection.UpgradeFrom, Connection.UpgradeTo| Constructor and Description |
|---|
HttpConnection(HttpConfiguration config,
Connector connector,
EndPoint endPoint,
HttpCompliance compliance,
boolean recordComplianceViolations) |
| Modifier and Type | Method and Description |
|---|---|
void |
abort(java.lang.Throwable failure)
Aborts this transport.
|
void |
asyncReadFillInterested() |
void |
blockingReadFailure(java.lang.Throwable e) |
void |
blockingReadFillInterested() |
protected boolean |
fillAndParseForContent()
Fill and parse data looking for content
|
private int |
fillRequestBuffer() |
long |
getBytesIn() |
long |
getBytesOut() |
Connector |
getConnector() |
static HttpConnection |
getCurrentConnection()
Get the current connection that this thread is dispatched to.
|
HttpGenerator |
getGenerator() |
HttpChannel |
getHttpChannel() |
HttpConfiguration |
getHttpConfiguration() |
long |
getMessagesIn() |
long |
getMessagesOut() |
HttpParser |
getParser() |
java.nio.ByteBuffer |
getRequestBuffer() |
Server |
getServer() |
boolean |
isOptimizedForDirectBuffers()
Is the underlying transport optimized for DirectBuffer usage
|
boolean |
isPushSupported() |
boolean |
isRecordHttpComplianceViolations() |
boolean |
isRequestBufferEmpty() |
(package private) HttpInput.Content |
newContent(java.nio.ByteBuffer c) |
protected HttpChannelOverHttp |
newHttpChannel() |
protected HttpGenerator |
newHttpGenerator() |
protected HttpParser |
newHttpParser(HttpCompliance compliance) |
protected HttpParser.RequestHandler |
newRequestHandler() |
void |
onClose()
Callback method invoked when this connection is closed.
|
void |
onCompleted()
Called to indicated the end of the current request/response cycle (which may be
some time after the last content is sent).
|
void |
onFillable()
Callback method invoked when the endpoint is ready to be read.
|
protected void |
onFillInterestedFailed(java.lang.Throwable cause)
Callback method invoked when the endpoint failed to be ready to be read.
|
void |
onFlushed(long bytes)
Invoked when a
WriteFlusher 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(java.lang.Throwable timeout)
Callback method invoked when the endpoint failed to be ready to be read after a timeout
|
java.nio.ByteBuffer |
onUpgradeFrom()
Takes the input buffer from the connection on upgrade.
|
private boolean |
parseRequestBuffer() |
void |
push(MetaData.Request request) |
(package private) void |
releaseRequestBuffer() |
void |
run() |
void |
send(MetaData.Response info,
boolean head,
java.nio.ByteBuffer content,
boolean lastContent,
Callback callback)
Asynchronous call to send a response (or part) over the transport
|
protected static HttpConnection |
setCurrentConnection(HttpConnection connection) |
java.lang.String |
toConnectionString() |
addListener, close, failedCallback, fillInterested, getCreatedTimeStamp, getEndPoint, getExecutor, getInputBufferSize, isFillInterested, onIdleExpired, removeListener, setInputBufferSize, toString, tryFillInterested, tryFillInterestedprivate static final Logger LOG
public static final HttpField CONNECTION_CLOSE
public static final java.lang.String UPGRADE_CONNECTION_ATTRIBUTE
private static final boolean REQUEST_BUFFER_DIRECT
private static final boolean HEADER_BUFFER_DIRECT
private static final boolean CHUNK_BUFFER_DIRECT
private static final java.lang.ThreadLocal<HttpConnection> __currentConnection
private final HttpConfiguration _config
private final Connector _connector
private final ByteBufferPool _bufferPool
private final HttpInput _input
private final HttpGenerator _generator
private final HttpChannelOverHttp _channel
private final HttpParser _parser
private final java.util.concurrent.atomic.AtomicInteger _contentBufferReferences
private volatile java.nio.ByteBuffer _requestBuffer
private volatile java.nio.ByteBuffer _chunk
private final HttpConnection.BlockingReadCallback _blockingReadCallback
private final HttpConnection.AsyncReadCallback _asyncReadCallback
private final HttpConnection.SendCallback _sendCallback
private final boolean _recordHttpComplianceViolations
private final java.util.concurrent.atomic.LongAdder bytesIn
private final java.util.concurrent.atomic.LongAdder bytesOut
public HttpConnection(HttpConfiguration config, Connector connector, EndPoint endPoint, HttpCompliance compliance, boolean recordComplianceViolations)
public static HttpConnection getCurrentConnection()
for a more general way to access the HttpConnectionprotected static HttpConnection setCurrentConnection(HttpConnection connection)
public HttpConfiguration getHttpConfiguration()
public boolean isRecordHttpComplianceViolations()
protected HttpGenerator newHttpGenerator()
protected HttpChannelOverHttp newHttpChannel()
protected HttpParser newHttpParser(HttpCompliance compliance)
protected HttpParser.RequestHandler newRequestHandler()
public Server getServer()
public Connector getConnector()
public HttpChannel getHttpChannel()
public HttpParser getParser()
public HttpGenerator getGenerator()
public boolean isOptimizedForDirectBuffers()
HttpTransportisOptimizedForDirectBuffers in interface HttpTransportpublic long getMessagesIn()
getMessagesIn in interface ConnectiongetMessagesIn in class AbstractConnectionpublic long getMessagesOut()
getMessagesOut in interface ConnectiongetMessagesOut in class AbstractConnectionpublic java.nio.ByteBuffer onUpgradeFrom()
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.
onUpgradeFrom in interface Connection.UpgradeFrompublic void onFlushed(long bytes)
throws java.io.IOException
WriteFlusher.ListenerInvoked 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.
onFlushed in interface WriteFlusher.Listenerbytes - the number of bytes flushedjava.io.IOException - if the write should failvoid releaseRequestBuffer()
public java.nio.ByteBuffer getRequestBuffer()
public boolean isRequestBufferEmpty()
public void onFillable()
AbstractConnectionCallback method invoked when the endpoint is ready to be read.
onFillable in class AbstractConnectionAbstractConnection.fillInterested()protected boolean fillAndParseForContent()
HttpParser.RequestHandler method was called and it returned true;private int fillRequestBuffer()
private boolean parseRequestBuffer()
public void onCompleted()
HttpTransportonCompleted in interface HttpTransportprotected boolean onReadTimeout(java.lang.Throwable timeout)
AbstractConnectionCallback method invoked when the endpoint failed to be ready to be read after a timeout
onReadTimeout in class AbstractConnectiontimeout - the cause of the read timeoutprotected void onFillInterestedFailed(java.lang.Throwable cause)
AbstractConnectionCallback method invoked when the endpoint failed to be ready to be read.
onFillInterestedFailed in class AbstractConnectioncause - the exception that caused the failurepublic void onOpen()
ConnectionCallback method invoked when this connection is opened.
Creators of the connection implementation are responsible for calling this method.
onOpen in interface ConnectiononOpen in class AbstractConnectionpublic void onClose()
ConnectionCallback method invoked when this connection is closed.
Creators of the connection implementation are responsible for calling this method.
onClose in interface ConnectiononClose in class AbstractConnectionpublic void run()
run in interface java.lang.Runnablepublic void send(MetaData.Response info, boolean head, java.nio.ByteBuffer content, boolean lastContent, Callback callback)
HttpTransportsend in interface HttpTransportinfo - 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.head - True if the response if for a HEAD request (and the data should not be sent).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 onHttpInput.Content newContent(java.nio.ByteBuffer c)
public void abort(java.lang.Throwable failure)
HttpTransportThis 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
abort in interface HttpTransportfailure - the failure that caused the abort.public boolean isPushSupported()
isPushSupported in interface HttpTransportpublic void push(MetaData.Request request)
push in interface HttpTransportrequest - A request to use as the basis for generating a pushed response.public void asyncReadFillInterested()
public void blockingReadFillInterested()
public void blockingReadFailure(java.lang.Throwable e)
public long getBytesIn()
getBytesIn in interface ConnectiongetBytesIn in class AbstractConnectionpublic long getBytesOut()
getBytesOut in interface ConnectiongetBytesOut in class AbstractConnectionpublic java.lang.String toConnectionString()
toConnectionString in class AbstractConnection