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 HTTPServerStream
s
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 TypeMethodDescriptionvoid
close()
Terminates thisHTTPServer
at 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 thisHTTPServer
is associated with.default boolean
Returnstrue
if server push is supported and enabled.void
onNewRequest
(Consumer<HTTPServerStream> callback) Sets the callback that is called when a newHTTPServerStream
was created after receiving a request from the client.void
receive
(byte[] data) Called by the application when it receives data from the client connection thisHTTPServer
is 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 thisHTTPServer
is 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 thisHTTPServer
is associated with.- Returns:
- The connection
-
close
void close()Terminates thisHTTPServer
at any time, causing no further callbacks to be called and the connection to be terminated.Calling this method also closes all active requests.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
isServerPushEnabled
default boolean isServerPushEnabled()Returnstrue
if server push is supported and enabled.- Returns:
true
if server push is available
-
onNewRequest
Sets the callback that is called when a newHTTPServerStream
was created after receiving a request from the client.No callbacks in the
HTTPServerStream
are 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 allHTTPServerStream
s which have not received a complete response yet.- Returns:
- The collection of active
HTTPServerStream
s
-