Interface ServerSentEventServer.RequestHandler
- Enclosing interface:
ServerSentEventServer
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
ServerSentEventServer
implementations.
This is used internally by Soklet
instances to "talk" to a ServerSentEventServer
via ServerSentEventServer.initialize(SokletConfiguration, RequestHandler)
.
It's the responsibility of the ServerSentEventServer
to implement HTTP mechanics: read bytes from the request, write bytes to the response, and so forth.
Most Soklet applications will use DefaultServerSentEventServer
and therefore do not need to implement this interface directly.
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionvoid
handleRequest
(Request request, Consumer<RequestResult> requestResultConsumer) Callback to be invoked by aServerSentEventServer
implementation after it has received a Server-Sent Event Source HTTP request but prior to writing initial data to the HTTP response.
-
Method Details
-
handleRequest
void handleRequest(@Nonnull Request request, @Nonnull Consumer<RequestResult> requestResultConsumer) Callback to be invoked by aServerSentEventServer
implementation after it has received a Server-Sent Event Source HTTP request but prior to writing initial data to the HTTP response.Note: this method is only invoked during the initial request "handshake" - it is not called for subsequent Server-Sent Event stream writes performed via
ServerSentEventBroadcaster.broadcast(ServerSentEvent)
invocations.For example, when a Server-Sent Event Source HTTP request is received, you might immediately write an HTTP 200 OK response if all looks good, or reject with a 401 due to invalid credentials. That is the extent of the request-handling logic performed here. The Server-Sent Event stream then remains open and can be written to via
ServerSentEventBroadcaster.broadcast(ServerSentEvent)
.The
ServerSentEventServer
is responsible for converting its internal request representation into aRequest
, which aSoklet
instance consumes and performs Soklet application request processing logic.The
Soklet
instance will generate aMarshaledResponse
for the request, which it "hands back" to theServerSentEventServer
to be sent over the wire to the client.- Parameters:
request
- a SokletRequest
representation of theServerSentEventServer
's internal HTTP request datarequestResultConsumer
- invoked bySoklet
when it's time for theServerSentEventServer
to write HTTP response data to the client
-