Class HttpReceiver
- java.lang.Object
-
- org.eclipse.jetty.client.HttpReceiver
-
- Direct Known Subclasses:
HttpReceiverOverFCGI
,HttpReceiverOverHTTP
,HttpReceiverOverHTTP2
public abstract class HttpReceiver extends java.lang.Object
HttpReceiver
provides the abstract code to implement the various steps of the receive of HTTP responses.HttpReceiver
maintains a state machine that is updated when the steps of receiving a response are executed.Subclasses must handle the transport-specific details, for example how to read from the raw socket and how to parse the bytes read from the socket. Then they have to call the methods defined in this class in the following order:
responseBegin(HttpExchange)
, when the HTTP response data containing the HTTP status code is availableresponseHeader(HttpExchange, HttpField)
, when an HTTP field is availableresponseHeaders(HttpExchange)
, when all HTTP headers are availableresponseContent(HttpExchange, ByteBuffer, Callback)
, when HTTP content is availableresponseSuccess(HttpExchange)
, when the response is successful
responseFailure(Throwable)
to indicate that the response has failed (for example, because of I/O exceptions). At any time, user threads may abort the response which will causeresponseFailure(Throwable)
to be invoked.The state machine maintained by this class ensures that the response steps are not executed by an I/O thread if the response has already been failed.
- See Also:
HttpSender
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HttpReceiver(HttpChannel channel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
abort(HttpExchange exchange, java.lang.Throwable failure)
protected long
demand()
protected void
dispose()
Disposes the state of this HttpReceiver.protected HttpChannel
getHttpChannel()
protected HttpDestination
getHttpDestination()
protected HttpExchange
getHttpExchange()
protected boolean
hasDemandOrStall()
boolean
isFailed()
protected void
receive()
protected void
reset()
Resets the state of this HttpReceiver.protected boolean
responseBegin(HttpExchange exchange)
Method to be invoked when the response status code is available.protected boolean
responseContent(HttpExchange exchange, java.nio.ByteBuffer buffer, Callback callback)
Method to be invoked when response HTTP content is available.protected boolean
responseFailure(java.lang.Throwable failure)
Method to be invoked when the response is failed.protected boolean
responseHeader(HttpExchange exchange, HttpField field)
Method to be invoked when a response HTTP header is available.protected boolean
responseHeaders(HttpExchange exchange)
Method to be invoked after all response HTTP headers are available.protected boolean
responseSuccess(HttpExchange exchange)
Method to be invoked when the response is successful.protected void
storeCookie(java.net.URI uri, HttpField field)
java.lang.String
toString()
-
-
-
Field Detail
-
LOG
protected static final Logger LOG
-
-
Constructor Detail
-
HttpReceiver
protected HttpReceiver(HttpChannel channel)
-
-
Method Detail
-
getHttpChannel
protected HttpChannel getHttpChannel()
-
demand
protected long demand()
-
hasDemandOrStall
protected boolean hasDemandOrStall()
-
getHttpExchange
protected HttpExchange getHttpExchange()
-
getHttpDestination
protected HttpDestination getHttpDestination()
-
isFailed
public boolean isFailed()
-
receive
protected void receive()
-
responseBegin
protected boolean responseBegin(HttpExchange exchange)
Method to be invoked when the response status code is available.Subclasses must have set the response status code on the
Response
object of theHttpExchange
prior invoking this method.This method takes case of notifying
Response.BeginListener
s.- Parameters:
exchange
- the HTTP exchange- Returns:
- whether the processing should continue
-
responseHeader
protected boolean responseHeader(HttpExchange exchange, HttpField field)
Method to be invoked when a response HTTP header is available.Subclasses must not have added the header to the
Response
object of theHttpExchange
prior invoking this method.This method takes case of notifying
Response.HeaderListener
s and storing cookies.- Parameters:
exchange
- the HTTP exchangefield
- the response HTTP field- Returns:
- whether the processing should continue
-
storeCookie
protected void storeCookie(java.net.URI uri, HttpField field)
-
responseHeaders
protected boolean responseHeaders(HttpExchange exchange)
Method to be invoked after all response HTTP headers are available.This method takes case of notifying
Response.HeadersListener
s.- Parameters:
exchange
- the HTTP exchange- Returns:
- whether the processing should continue
-
responseContent
protected boolean responseContent(HttpExchange exchange, java.nio.ByteBuffer buffer, Callback callback)
Method to be invoked when response HTTP content is available.This method takes case of decoding the content, if necessary, and notifying
Response.ContentListener
s.- Parameters:
exchange
- the HTTP exchangebuffer
- the response HTTP content buffercallback
- the callback- Returns:
- whether the processing should continue
-
responseSuccess
protected boolean responseSuccess(HttpExchange exchange)
Method to be invoked when the response is successful.This method takes case of notifying
Response.SuccessListener
s and possiblyResponse.CompleteListener
s (if the exchange is completed).- Parameters:
exchange
- the HTTP exchange- Returns:
- whether the response was processed as successful
-
responseFailure
protected boolean responseFailure(java.lang.Throwable failure)
Method to be invoked when the response is failed.This method takes care of notifying
Response.FailureListener
s.- Parameters:
failure
- the response failure- Returns:
- whether the response was processed as failed
-
reset
protected void reset()
Resets the state of this HttpReceiver.Subclasses should override (but remember to call
super
) to reset their own state.Either this method or
dispose()
is called.
-
dispose
protected void dispose()
Disposes the state of this HttpReceiver.Subclasses should override (but remember to call
super
) to dispose their own state.Either this method or
reset()
is called.
-
abort
public boolean abort(HttpExchange exchange, java.lang.Throwable failure)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-