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 voidendRequest(HTTPMessageTrailers trailers) Ends this request, allowing the server to send the response.Returns theHTTPClientthat created thisHTTPClientStream.Returns the received response of thisHTTPClientStream, ornullif no response was received yet.voidonResponse(Consumer<HTTPResponse> onResponse) Sets a callback that is called when thisHTTPClientStreamreceives a response.voidonResponseData(Consumer<HTTPResponseData> onResponseData) Sets a callback that is called when thisHTTPClientStreamreceives data for the response.voidonResponseEnded(Consumer<HTTPMessageTrailers> onResponseEnded) Sets a callback that is called when thisHTTPClientStreamhas finished receiving the response and data, including optional trailers.default voidonServerPush(Consumer<HTTPClientStream> onServerPush) Sets a callback that is called when thisHTTPClientStreamreceives a pushed request.booleansendRequestData(byte[] data, boolean lastPacket) Streams request data.voidStarts 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 theHTTPClientthat 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-trueif this is the last piece of data being sent- Returns:
trueif the underlying connection is writable,falseif 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 thisHTTPClientStreamreceives a pushed request.This callback is always called before the
onResponsecallback. If the underlying protocol does not support server push, this callback is never called.The new
HTTPClientStreampassed to the callback is used to receive the pushed response. The methodsstartRequest(),sendRequestData(byte[], boolean), andendRequest(HTTPMessageTrailers)should not be called on thisHTTPClientStream. TheonResponsecallback will be called as soon as the pushed response is received.- Parameters:
onServerPush- The callback
-
getResponse
HTTPResponse getResponse()Returns the received response of thisHTTPClientStream, ornullif no response was received yet.- Returns:
- The response
-
onResponse
Sets a callback that is called when thisHTTPClientStreamreceives a response.No other callbacks in this
HTTPClientStreamare 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 thisHTTPClientStreamreceives data for the response.If
HTTPMessageData.isLastPacket()istruefor aHTTPResponseDataobject passed to the callback, it is followed by aonResponseEndedcallback.- Parameters:
onResponseData- The callback
-
onResponseEnded
Sets a callback that is called when thisHTTPClientStreamhas finished receiving the response and data, including optional trailers.If this callback is called, this
HTTPClientStreamis implicitly closed and no further callbacks will be called.- Parameters:
onResponseEnded- The callback
-