httpResponseHandler function
dynamic
httpResponseHandler(
- dynamic payload,
- HttpRequest request
)
Implementation
dynamic httpResponseHandler(
dynamic payload,
HttpRequest request,
) {
/// Websocket handler will return websocket payload
/// and in this case we need to remain the connection open for
/// websocket communication. So there is no `res.close()` required.
if (payload is WebSocket) {
return;
}
/// If there is responseHandler set, handle responseHandler
/// before DoxResponse process. The responseHandler will return
/// DoxResponse to process
ResponseHandlerInterface? customResponseHandler = DoxServer().responseHandler;
if (customResponseHandler != null) {
DoxResponse doxResponse = customResponseHandler
.handle(payload is DoxResponse ? payload : DoxResponse(payload));
payload = doxResponse;
}
/// If payload is DoxResponse, DoxResponse have process function
/// which will set header and status code in the response
/// and will pass payload/content to `responseDataHandler` function.
if (payload is DoxResponse) {
payload.process(request);
return;
}
}