Class HttpSender
- java.lang.Object
-
- org.eclipse.jetty.client.HttpSender
-
- All Implemented Interfaces:
java.util.EventListener
,AsyncContentProvider.Listener
- Direct Known Subclasses:
HttpSenderOverFCGI
,HttpSenderOverHTTP
,HttpSenderOverHTTP2
public abstract class HttpSender extends java.lang.Object implements AsyncContentProvider.Listener
HttpSender
abstracts the algorithm to send HTTP requests, so that subclasses only implement the transport-specific code to send requests over the wire, implementingsendHeaders(HttpExchange, HttpContent, Callback)
andsendContent(HttpExchange, HttpContent, Callback)
.HttpSender
governs two state machines.The request state machine is updated by
HttpSender
as the various steps of sending a request are executed, seeRequestState
. At any point in time, a user thread may abort the request, which may (if the request has not been completely sent yet) move the request state machine toRequestState#FAILURE
. The request state machine guarantees that the request steps are executed (by I/O threads) only if the request has not been failed already.The sender state machine is updated by
HttpSender
from three sources: deferred content notifications (viaonContent()
), 100-continue notifications (viaproceed(HttpExchange, Throwable)
) and normal request send (viasendContent(HttpExchange, HttpContent, Callback)
). This state machine must guarantee that the request sending is never executed concurrently: only one of those sources may trigger the call tosendContent(HttpExchange, HttpContent, Callback)
.- See Also:
HttpReceiver
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HttpSender(HttpChannel channel)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
abort(HttpExchange exchange, java.lang.Throwable failure)
protected boolean
beginToHeaders(HttpExchange exchange)
protected void
dispose()
protected boolean
expects100Continue(Request request)
protected HttpChannel
getHttpChannel()
protected HttpExchange
getHttpExchange()
protected boolean
headersToCommit(HttpExchange exchange)
boolean
isFailed()
void
onContent()
Callback method invoked when content is availablevoid
proceed(HttpExchange exchange, java.lang.Throwable failure)
protected boolean
queuedToBegin(HttpExchange exchange)
protected void
reset()
void
send(HttpExchange exchange)
protected abstract void
sendContent(HttpExchange exchange, HttpContent content, Callback callback)
Implementations should send the content at theHttpContent
cursor position over the wire.protected abstract void
sendHeaders(HttpExchange exchange, HttpContent content, Callback callback)
Implementations should send the HTTP headers over the wire, possibly with some content, in a single write, and notify the givencallback
of the result of this operation.protected boolean
someToContent(HttpExchange exchange, java.nio.ByteBuffer content)
protected boolean
someToSuccess(HttpExchange exchange)
java.lang.String
toString()
-
-
-
Field Detail
-
LOG
protected static final Logger LOG
-
-
Constructor Detail
-
HttpSender
protected HttpSender(HttpChannel channel)
-
-
Method Detail
-
getHttpChannel
protected HttpChannel getHttpChannel()
-
getHttpExchange
protected HttpExchange getHttpExchange()
-
isFailed
public boolean isFailed()
-
onContent
public void onContent()
Description copied from interface:AsyncContentProvider.Listener
Callback method invoked when content is available- Specified by:
onContent
in interfaceAsyncContentProvider.Listener
-
send
public void send(HttpExchange exchange)
-
expects100Continue
protected boolean expects100Continue(Request request)
-
queuedToBegin
protected boolean queuedToBegin(HttpExchange exchange)
-
beginToHeaders
protected boolean beginToHeaders(HttpExchange exchange)
-
headersToCommit
protected boolean headersToCommit(HttpExchange exchange)
-
someToContent
protected boolean someToContent(HttpExchange exchange, java.nio.ByteBuffer content)
-
someToSuccess
protected boolean someToSuccess(HttpExchange exchange)
-
sendHeaders
protected abstract void sendHeaders(HttpExchange exchange, HttpContent content, Callback callback)
Implementations should send the HTTP headers over the wire, possibly with some content, in a single write, and notify the givencallback
of the result of this operation.If there is more content to send, then
sendContent(HttpExchange, HttpContent, Callback)
will be invoked.- Parameters:
exchange
- the exchange to sendcontent
- the content to sendcallback
- the callback to notify
-
sendContent
protected abstract void sendContent(HttpExchange exchange, HttpContent content, Callback callback)
Implementations should send the content at theHttpContent
cursor position over the wire.The
HttpContent
cursor is advanced by HttpSender at the right time, and if more content needs to be sent, this method is invoked again; subclasses need only to send the content at theHttpContent
cursor position.This method is invoked one last time when
HttpContent.isConsumed()
is true and therefore there is no actual content to send. This is done to allow subclasses to write "terminal" bytes (such as the terminal chunk when the transfer encoding is chunked) if their protocol needs to.- Parameters:
exchange
- the exchange to sendcontent
- the content to sendcallback
- the callback to notify
-
reset
protected void reset()
-
dispose
protected void dispose()
-
proceed
public void proceed(HttpExchange exchange, java.lang.Throwable failure)
-
abort
public boolean abort(HttpExchange exchange, java.lang.Throwable failure)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-