Interface HTTPClientStream
- All Superinterfaces:
AutoCloseable
,Closeable
,HTTPMessageStream
- All Known Implementing Classes:
AbstractHTTPClientStream
HTTPClientStream
represents a single HTTP request transaction from the perspective of the client, including the outgoing HTTPRequest
and its data,
and is used for receiving the corresponding response.- Since:
- 1.4.1
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
endRequest
(HTTPMessageTrailers trailers) Ends this request, allowing the server to send the response.Returns theHTTPClient
that created thisHTTPClientStream
.Returns the received response of thisHTTPClientStream
, ornull
if no response was received yet.void
onResponse
(Consumer<HTTPResponse> onResponse) Sets a callback that is called when thisHTTPClientStream
receives a response.void
onResponseData
(Consumer<HTTPResponseData> onResponseData) Sets a callback that is called when thisHTTPClientStream
receives data for the response.void
onResponseEnded
(Consumer<HTTPMessageTrailers> onResponseEnded) Sets a callback that is called when thisHTTPClientStream
has finished receiving the response and data, including optional trailers.default void
onServerPush
(Consumer<HTTPClientStream> onServerPush) Sets a callback that is called when thisHTTPClientStream
receives a pushed request.boolean
sendRequestData
(byte[] data, boolean lastPacket) Streams request data.void
Starts the request passed in a constructor.Methods inherited from interface org.omegazero.http.util.HTTPMessageStream
close, close, getRequest, isClosed, onError, onWritable, setReceiveData
-
Method Details
-
getClient
HTTPClient getClient()Returns theHTTPClient
that created thisHTTPClientStream
.- Returns:
- The
HTTPClient
-
startRequest
void startRequest()Starts the request passed in a constructor.This method must be followed by at least one call to
sendRequestData(byte[], boolean)
orendRequest(HTTPMessageTrailers)
.- Throws:
IllegalStateException
- If this method was called already (optional)
-
sendRequestData
boolean sendRequestData(byte[] data, boolean lastPacket) Streams request data.- Parameters:
data
- The datalastPacket
-true
if this is the last piece of data being sent- Returns:
true
if the underlying connection is writable,false
if the write buffer is full and data will have to be queued- Throws:
IllegalStateException
- If the request has ended already (optional)- See Also:
-
endRequest
Ends this request, allowing the server to send the response. Optional trailers are sent with the request, if supported.- Parameters:
trailers
- If notnull
, the trailers to send
-
onServerPush
Sets a callback that is called when thisHTTPClientStream
receives a pushed request.This callback is always called before the
onResponse
callback. If the underlying protocol does not support server push, this callback is never called.The new
HTTPClientStream
passed to the callback is used to receive the pushed response. The methodsstartRequest()
,sendRequestData(byte[], boolean)
, andendRequest(HTTPMessageTrailers)
should not be called on thisHTTPClientStream
. TheonResponse
callback will be called as soon as the pushed response is received.- Parameters:
onServerPush
- The callback
-
getResponse
HTTPResponse getResponse()Returns the received response of thisHTTPClientStream
, ornull
if no response was received yet.- Returns:
- The response
-
onResponse
Sets a callback that is called when thisHTTPClientStream
receives a response.No other callbacks in this
HTTPClientStream
are called before the given callback has returned.This callback may be called multiple times when receiving multiple responses (for example, a 102 Processing followed by the actual response, see also:
HTTPResponse.isIntermediateMessage()
).- Parameters:
onResponse
- The callback
-
onResponseData
Sets a callback that is called when thisHTTPClientStream
receives data for the response.If
HTTPMessageData.isLastPacket()
istrue
for aHTTPResponseData
object passed to the callback, it is followed by aonResponseEnded
callback.- Parameters:
onResponseData
- The callback
-
onResponseEnded
Sets a callback that is called when thisHTTPClientStream
has finished receiving the response and data, including optional trailers.If this callback is called, this
HTTPClientStream
is implicitly closed and no further callbacks will be called.- Parameters:
onResponseEnded
- The callback
-