#include <userver/server/websocket/websocket_handler.hpp>
Base class for WebSocket handler.
Static options:
Inherits all the options from server::handlers::HandlerBase and adds the following ones:
Name | Description | Default value |
log-level | overrides log level for this handle | <no override> |
status-codes-log-level | map of "status": log_level items to override span log level for specific status codes | {} |
max-remote-payload | max remote payload size | 65536 |
fragment-size | max output fragment size | 65536 |
Example usage:
namespace samples::websocket {
public:
static constexpr std::string_view kName = "websocket-handler";
using WebsocketHandlerBase::WebsocketHandlerBase;
chat.
Send(std::move(message));
}
}
};
}
- Examples
- samples/websocket_service/websocket_service.cpp.
Definition at line 37 of file websocket_handler.hpp.
|
| WebsocketHandlerBase (const components::ComponentConfig &, const components::ComponentContext &) |
|
virtual void | Handle (WebSocketConnection &websocket, server::request::RequestContext &) const =0 |
| Websocket handler code belongs here.
|
|
virtual bool | HandleHandshake (const server::http::HttpRequest &, server::http::HttpResponse &, server::request::RequestContext &) const |
| If any code is required for handshake validation, it goes here.
|
|
virtual void | HandleNonWebsocketRequest (const server::http::HttpRequest &request, server::request::RequestContext &context) const |
| If request isn't a websocket request the function handles a request.
|
|
void | PrepareAndHandleRequest (http::HttpRequest &request, request::RequestContext &context) const override |
|
void | ReportMalformedRequest (http::HttpRequest &request) const final |
|
virtual const std::string & | HandlerName () const |
|
const std::vector< http::HttpMethod > & | GetAllowedMethods () const |
|
virtual logging::Level | GetLogLevelForResponseStatus (http::HttpStatus status) const |
|
virtual FormattedErrorData | GetFormattedExternalErrorBody (const CustomHandlerException &exc) const |
|
std::string | GetResponseDataForLoggingChecked (const http::HttpRequest &request, request::RequestContext &context, const std::string &response_data) const |
|
void | HandleCustomHandlerException (const http::HttpRequest &request, const CustomHandlerException &ex) const |
|
void | HandleUnknownException (const http::HttpRequest &request, const std::exception &ex) const |
|
void | LogUnknownException (const std::exception &ex, std::optional< logging::Level > log_level_override={}) const |
| Helper function to log an unknown exception.
|
|
const std::optional< logging::Level > & | GetLogLevel () const |
| Returns the default log level for the handler.
|
|
bool | IsMonitor () const |
| Returns whether this is a monitoring handler.
|
|
const HandlerConfig & | GetConfig () const |
| Returns handler config.
|
|
ComponentHealth | GetComponentHealth () const override |
|
void | OnLoadingCancelled () override |
|
void | OnAllComponentsLoaded () override |
|
void | OnAllComponentsAreStopping () override |
|
◆ ClientError
◆ ExternalBody
◆ HandlerErrorCode
◆ InternalMessage
◆ InternalServerError
◆ LoggableComponentBase
◆ GetComponentHealth()
ComponentHealth components::ComponentBase::GetComponentHealth |
( |
| ) |
const |
|
inlineoverridevirtualinherited |
◆ GetLogLevelForResponseStatus()
Override it if you need a custom logging level for messages about finish of request handling for some http statuses.
◆ GetRequestBodyForLogging()
|
protectedvirtualinherited |
◆ GetResponseDataForLogging()
|
protectedvirtualinherited |
◆ HandleCustomHandlerException()
Takes the exception and formats it into response, as specified by exception.
◆ HandleHandshake()
If any code is required for handshake validation, it goes here.
Definition at line 47 of file websocket_handler.hpp.
◆ HandleNonWebsocketRequest()
If request isn't a websocket request the function handles a request.
Definition at line 60 of file websocket_handler.hpp.
◆ HandleRequest()
|
protectedvirtualinherited |
◆ HandleStreamRequest()
|
protectedvirtualinherited |
The core method for HTTP request handling. request
arg contains HTTP headers, full body, etc. The response body is passed in parts to ResponseBodyStream
. Stream transmission is useful when: 1) The body size is unknown beforehand. 2) The client may take advantage of early body transmission (e.g. a Web Browser may start rendering the HTML page or downloading dependant resources). 3) The body size is huge and we want to have only a part of it in memory.
- Note
- It is used only if IsStreamed() returned
true
.
◆ HandleUnknownException()
void server::handlers::HttpHandlerBase::HandleUnknownException |
( |
const http::HttpRequest & | request, |
|
|
const std::exception & | ex ) const |
|
inherited |
Takes the exception and formats it into response as an internal server error.
◆ IsMethodStatisticIncluded()
virtual bool server::handlers::HttpHandlerBase::IsMethodStatisticIncluded |
( |
| ) |
const |
|
inlineprotectedvirtualinherited |
Override it to show per HTTP-method statistics besides statistics for all methods
Definition at line 156 of file http_handler_base.hpp.
◆ IsMonitor()
bool server::handlers::HandlerBase::IsMonitor |
( |
| ) |
const |
|
inlineinherited |
Returns whether this is a monitoring handler.
Definition at line 67 of file handler_base.hpp.
◆ IsStreamed()
virtual bool server::handlers::HttpHandlerBase::IsStreamed |
( |
| ) |
const |
|
inlineprotectedvirtualinherited |
◆ NeedCheckAuth()
virtual bool server::handlers::HttpHandlerBase::NeedCheckAuth |
( |
| ) |
const |
|
inlineprotectedvirtualinherited |
Override it if you want to disable auth checks in handler by some condition
Definition at line 160 of file http_handler_base.hpp.
◆ OnAllComponentsAreStopping()
void components::ComponentBase::OnAllComponentsAreStopping |
( |
| ) |
|
|
inlineoverridevirtualinherited |
◆ OnAllComponentsLoaded()
void components::ComponentBase::OnAllComponentsLoaded |
( |
| ) |
|
|
inlineoverridevirtualinherited |
◆ OnLoadingCancelled()
void components::ComponentBase::OnLoadingCancelled |
( |
| ) |
|
|
inlineoverridevirtualinherited |
Called once if the creation of any other component failed. If the current component expects some other component to take any action with the current component, this call is a signal that such action may never happen due to components loading was cancelled. Application components might not want to override it.
Reimplemented from components::RawComponentBase.
Definition at line 42 of file component_base.hpp.
◆ ParseRequestData()
|
inlineprotectedvirtualinherited |
◆ PrepareAndHandleRequest()
◆ ReportMalformedRequest()
void server::handlers::HttpHandlerBase::ReportMalformedRequest |
( |
http::HttpRequest & | | ) |
const |
|
finalvirtualinherited |
Produces response to a request unrecognized by the protocol based on provided generic response. Does not throw.
Reimplemented from server::handlers::HandlerBase.
The documentation for this class was generated from the following file: