Package org.omegazero.http.util
Interface HTTPServer
- All Superinterfaces:
AutoCloseable,Closeable,HTTPResponder
A
HTTPServer is associated with a single client connection from which it receives data, which is then processed to create HTTPServerStreams
usable by the application.- Since:
- 1.4.1
-
Field Summary
Fields inherited from interface org.omegazero.http.util.HTTPResponder
EMPTY_BYTE_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Terminates thisHTTPServerat any time, causing no further callbacks to be called and the connection to be terminated.Returns a (possibly unmodifiable) collection of all currently active request transactions managed by thisHTTPServer.Returns the client connection thisHTTPServeris associated with.default booleanReturnstrueif server push is supported and enabled.voidonNewRequest(Consumer<HTTPServerStream> callback) Sets the callback that is called when a newHTTPServerStreamwas created after receiving a request from the client.voidreceive(byte[] data) Called by the application when it receives data from the client connection thisHTTPServeris associated with.Methods inherited from interface org.omegazero.http.util.HTTPResponder
respond, respond
-
Method Details
-
receive
void receive(byte[] data) Called by the application when it receives data from the client connection thisHTTPServeris associated with.Any protocol errors caused by malformed data passed to this method should be handled internally (for example, simply closing the connection is an appropriate minimum action).
- Parameters:
data- The data
-
getConnection
WritableSocket getConnection()Returns the client connection thisHTTPServeris associated with.- Returns:
- The connection
-
close
void close()Terminates thisHTTPServerat any time, causing no further callbacks to be called and the connection to be terminated.Calling this method also closes all
.invalid reference
active requests
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isServerPushEnabled
default boolean isServerPushEnabled()Returnstrueif server push is supported and enabled.- Returns:
trueif server push is available
-
onNewRequest
Sets the callback that is called when a newHTTPServerStreamwas created after receiving a request from the client.No callbacks in the
HTTPServerStreamare called before the given callback has returned.- Parameters:
callback- The callback- Implementation Note:
- The implementation should catch exceptions thrown by the callback and return a HTTP 500 error
-
getActiveRequests
Collection<HTTPServerStream> getActiveRequests()Returns a (possibly unmodifiable) collection of all currently active request transactions managed by thisHTTPServer. This is the set of allHTTPServerStreams which have not received a complete response yet.- Returns:
- The collection of active
HTTPServerStreams
-