Interface HTTPServerStream
- All Superinterfaces:
- AutoCloseable,- Closeable,- HTTPMessageStream
- All Known Implementing Classes:
- AbstractHTTPServerStream
HTTPServerStream represents a single HTTP request transaction from the perspective of the server, including the incoming HTTPRequest and its associated incoming data,
 and is used to send a corresponding response.- Since:
- 1.4.1
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptiondefault voidendResponse(HTTPMessageTrailers trailers) Ends the response with optional trailers, if supported.Returns theHTTPServerthat created thisHTTPServerStream.voidonRequestData(Consumer<HTTPRequestData> onRequestData) Sets a callback that is called when thisHTTPServerStreamreceives data for the request.voidonRequestEnded(Consumer<HTTPMessageTrailers> onRequestEnded) Sets a callback that is called when thisHTTPServerStreamhas finished receiving the request and data, including optional trailers.voidResponds to thisHTTPServerStreamwith a new HTTP response with the given status, data and headers, if no response was already sent.voidrespond(HTTPResponseData response) Responds to thisHTTPServerStreamwith the given full response, if no response was already sent.booleansendResponseData(byte[] data, boolean lastPacket) Streams response data after a call tostartResponse(HTTPResponse).voidstartResponse(HTTPResponse response) Starts a response with the given response header.default HTTPServerStreamstartServerPush(HTTPRequest request) Starts a server push stream with the given push request.Methods inherited from interface org.omegazero.http.util.HTTPMessageStreamclose, close, getRequest, isClosed, onError, onWritable, setReceiveData
- 
Method Details- 
getServerHTTPServer getServer()Returns theHTTPServerthat created thisHTTPServerStream.- Returns:
- The HTTPServer
 
- 
onRequestDataSets a callback that is called when thisHTTPServerStreamreceives data for the request.If HTTPMessageData.isLastPacket()istruefor aHTTPRequestDataobject passed to the callback, it is followed by aonRequestEndedcallback.- Parameters:
- onRequestData- The callback
 
- 
onRequestEndedSets a callback that is called when thisHTTPServerStreamhas finished receiving the request and data, including optional trailers.If this callback is called, it ends this HTTPServerStreamand no further callbacks will be called.- Parameters:
- onRequestEnded- The callback
 
- 
startServerPushStarts a server push stream with the given push request.This method must be called before startResponse(HTTPResponse). If server push is enabled, but no stream could be created because of limits set by the implementation or peer,nullis returned.The returned new HTTPServerStreamis used to send the pushed response the same way a regular response is sent. No callbacks will be called on thisHTTPServerStream.- Parameters:
- request- The push request
- Returns:
- The new HTTPServerStreamused to send the response, ornullif no new stream could be created
- Throws:
- UnsupportedOperationException- If server push is not supported or not enabled (- HTTPServer.isServerPushEnabled()returns- false)
 
- 
startResponseStarts a response with the given response header.Unlike the respondmethods, this does not end the response stream, but allows data to be streamed in multiple calls tosendResponseData(byte[], boolean).This method may be called multiple times, for example to send a 102 Processing response before the actual response. - Parameters:
- response- The response header
- Throws:
- IllegalStateException- If this method is called before the- onRequestEndedcallback (optional)
 
- 
sendResponseDataboolean sendResponseData(byte[] data, boolean lastPacket) Streams response data after a call tostartResponse(HTTPResponse).If lastPacket is true, the call closes thisHTTPServerStream.- Parameters:
- data- The data
- lastPacket-- 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 this method is called before the- onRequestEndedcallback (optional)
- See Also:
 
- 
endResponseEnds the response with optional trailers, if supported. This method implicitly closes thisHTTPServerStream.- Parameters:
- trailers- If not- null, the trailers to send
 
- 
respondResponds to thisHTTPServerStreamwith the given full response, if no response was already sent. This method implicitly closes thisHTTPServerStream.See HTTPResponder.respond(HTTPRequest, HTTPResponseData)for additional information.- Parameters:
- response- The response
- See Also:
 
- 
respondResponds to thisHTTPServerStreamwith a new HTTP response with the given status, data and headers, if no response was already sent. This method implicitly closes thisHTTPServerStream.See HTTPResponder.respond(HTTPRequest, int, byte[], String...)for additional information.- Parameters:
- status- The status code of the response
- data- The data to send in the response
- headers- Headers to send in the response
- See Also:
 
 
-