public abstract class AbstractHttpConnection extends AbstractConnection
A HttpConnection represents the connection of a HTTP client to the server
and is created by an instance of a Connector
. It's prime function is
to associate Request
and Response
instances with a EndPoint
.
A connection is also the prime mechanism used by jetty to recycle objects without
pooling. The Request
, Response
, HttpParser
, HttpGenerator
and HttpFields
instances are all recycled for the duraction of
a connection. Where appropriate, allocated buffers are also kept associated
with the connection via the parser and/or generator.
The connection state is held by 3 separate state machines: The request state, the response state and the continuation state. All three state machines must be driven to completion for every request, and all three can complete in any order.
The HttpConnection support protocol upgrade. If on completion of a request, the
response code is 101 (switch protocols), then the org.eclipse.jetty.io.Connection
request attribute is checked to see if there is a new Connection instance. If so,
the new connection is returned from handle()
and is used for future
handling of the underlying connection. Note that for switching protocols that
don't use 101 responses (eg CONNECT), the response should be sent and then the
status code changed to 101 before returning from the handler. Implementors
of new Connection types should be careful to extract any buffered data from
(HttpParser)http.getParser()).getHeaderBuffer() and
(HttpParser)http.getParser()).getBodyBuffer() to initialise their new connection.
Modifier and Type | Class and Description |
---|---|
class |
AbstractHttpConnection.Output |
class |
AbstractHttpConnection.OutputWriter |
Modifier and Type | Field and Description |
---|---|
protected Connector |
_connector |
protected Generator |
_generator |
protected javax.servlet.ServletInputStream |
_in |
protected AbstractHttpConnection.Output |
_out |
protected Parser |
_parser |
protected PrintWriter |
_printWriter |
protected Request |
_request |
protected HttpFields |
_requestFields |
protected Response |
_response |
protected HttpFields |
_responseFields |
protected Server |
_server |
protected HttpURI |
_uri |
protected AbstractHttpConnection.OutputWriter |
_writer |
_endp
Modifier | Constructor and Description |
---|---|
|
AbstractHttpConnection(Connector connector,
EndPoint endpoint,
Server server) |
protected |
AbstractHttpConnection(Connector connector,
EndPoint endpoint,
Server server,
Parser parser,
Generator generator,
Request request) |
Modifier and Type | Method and Description |
---|---|
void |
commitResponse(boolean last) |
void |
completeResponse() |
protected void |
content(Buffer buffer) |
void |
earlyEOF() |
void |
flushResponse() |
Object |
getAssociatedObject() |
Connector |
getConnector() |
static AbstractHttpConnection |
getCurrentConnection() |
Generator |
getGenerator() |
javax.servlet.ServletInputStream |
getInputStream()
Get the inputStream from the connection.
|
int |
getMaxIdleTime() |
javax.servlet.ServletOutputStream |
getOutputStream() |
Parser |
getParser() |
PrintWriter |
getPrintWriter(String encoding) |
Request |
getRequest() |
HttpFields |
getRequestFields() |
int |
getRequests() |
boolean |
getResolveNames() |
Response |
getResponse() |
HttpFields |
getResponseFields() |
Server |
getServer() |
abstract Connection |
handle()
Handle the connection.
|
protected void |
handleRequest() |
protected void |
headerComplete() |
void |
include() |
void |
included() |
boolean |
isConfidential(Request request)
Find out if the request supports CONFIDENTIAL security.
|
boolean |
isEarlyEOF() |
boolean |
isExpecting100Continues() |
boolean |
isExpecting102Processing() |
boolean |
isIdle() |
boolean |
isIncluding() |
boolean |
isIntegral(Request request)
Find out if the request supports INTEGRAL security.
|
boolean |
isResponseCommitted() |
boolean |
isSuspended()
The semantic of this method is to return true to indicate interest in further reads,
or false otherwise, but it is misnamed and should be really called
isReadInterested() . |
void |
messageComplete(long contentLength) |
protected HttpGenerator |
newHttpGenerator(Buffers responseBuffers,
EndPoint endPoint) |
protected HttpParser |
newHttpParser(Buffers requestBuffers,
EndPoint endpoint,
HttpParser.EventHandler requestHandler) |
void |
onClose()
Called after the connection is closed
|
protected void |
parsedHeader(Buffer name,
Buffer value) |
void |
reset() |
void |
setAssociatedObject(Object associatedObject) |
protected static void |
setCurrentConnection(AbstractHttpConnection connection) |
protected void |
startRequest(Buffer method,
Buffer uri,
Buffer version) |
String |
toString() |
getEndPoint, getTimeStamp, onIdleExpired
protected final Connector _connector
protected final Server _server
protected final HttpURI _uri
protected final Parser _parser
protected final HttpFields _requestFields
protected final Request _request
protected volatile javax.servlet.ServletInputStream _in
protected final Generator _generator
protected final HttpFields _responseFields
protected final Response _response
protected volatile AbstractHttpConnection.Output _out
protected volatile AbstractHttpConnection.OutputWriter _writer
protected volatile PrintWriter _printWriter
public AbstractHttpConnection(Connector connector, EndPoint endpoint, Server server)
public static AbstractHttpConnection getCurrentConnection()
protected static void setCurrentConnection(AbstractHttpConnection connection)
protected HttpParser newHttpParser(Buffers requestBuffers, EndPoint endpoint, HttpParser.EventHandler requestHandler)
protected HttpGenerator newHttpGenerator(Buffers responseBuffers, EndPoint endPoint)
public Parser getParser()
public int getRequests()
public Server getServer()
public Object getAssociatedObject()
public void setAssociatedObject(Object associatedObject)
associatedObject
- The associatedObject to set.public Connector getConnector()
public HttpFields getRequestFields()
public HttpFields getResponseFields()
public boolean isConfidential(Request request)
request
- the incoming HTTP requestConnector.isConfidential(Request)
, or false
if there is no connectorpublic boolean isIntegral(Request request)
request
- the incoming HTTP requestConnector.isIntegral(Request)
, or false
if there is no connectorpublic boolean getResolveNames()
false
(this method is not yet implemented)public Request getRequest()
public Response getResponse()
public javax.servlet.ServletInputStream getInputStream() throws IOException
If the associated response has the Expect header set to 100 Continue, then accessing the input stream indicates that the handler/servlet is ready for the request body and thus a 100 Continue response is sent.
IOException
- if the input stream cannot be retrievedpublic javax.servlet.ServletOutputStream getOutputStream()
public PrintWriter getPrintWriter(String encoding)
encoding
- the PrintWriter encodingPrintWriter
wrapping the output stream
. The writer is created if it
does not already exist.public boolean isResponseCommitted()
public boolean isEarlyEOF()
public void reset()
protected void handleRequest() throws IOException
IOException
public abstract Connection handle() throws IOException
Connection
IOException
- if the handling of I/O operations failpublic void commitResponse(boolean last) throws IOException
IOException
public void completeResponse() throws IOException
IOException
public void flushResponse() throws IOException
IOException
public Generator getGenerator()
public boolean isIncluding()
public void include()
public void included()
public boolean isIdle()
Connection.onIdleExpired(long)
public boolean isSuspended()
Connection
The semantic of this method is to return true to indicate interest in further reads,
or false otherwise, but it is misnamed and should be really called isReadInterested()
.
Connection.isSuspended()
public void onClose()
Connection
public boolean isExpecting100Continues()
public boolean isExpecting102Processing()
public int getMaxIdleTime()
public String toString()
toString
in class AbstractConnection
protected void startRequest(Buffer method, Buffer uri, Buffer version) throws IOException
IOException
protected void parsedHeader(Buffer name, Buffer value) throws IOException
IOException
protected void headerComplete() throws IOException
IOException
protected void content(Buffer buffer) throws IOException
IOException
public void messageComplete(long contentLength) throws IOException
IOException
public void earlyEOF()
Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.