userver: server::websocket::WebsocketHandlerBase Class Reference
Loading...
Searching...
No Matches
server::websocket::WebsocketHandlerBase Class Referenceabstract

#include <userver/server/websocket/websocket_handler.hpp>

Detailed Description

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 {
class WebsocketsHandler final : public server::websocket::WebsocketHandlerBase {
public:
// `kName` is used as the component name in static config
static constexpr std::string_view kName = "websocket-handler";
// Component is valid after construction and is able to accept requests
using WebsocketHandlerBase::WebsocketHandlerBase;
chat.Recv(message);
if (message.close_status) break;
chat.Send(std::move(message));
}
if (message.close_status) chat.Close(*message.close_status);
}
};
} // namespace samples::websocket
Examples
samples/websocket_service/websocket_service.cpp.

Definition at line 37 of file websocket_handler.hpp.

+ Inheritance diagram for server::websocket::WebsocketHandlerBase:
+ Collaboration diagram for server::websocket::WebsocketHandlerBase:

Public Member Functions

 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.
 
- Public Member Functions inherited from server::handlers::HttpHandlerBase
 HttpHandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
 
void HandleRequest (request::RequestBase &request, request::RequestContext &context) const override
 
void ReportMalformedRequest (request::RequestBase &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
 
- Public Member Functions inherited from server::handlers::HandlerBase
 HandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false)
 
bool IsMonitor () const
 Returns whether this is a monitoring handler.
 
const HandlerConfigGetConfig () const
 Returns handler config.
 
- Public Member Functions inherited from components::LoggableComponentBase
 LoggableComponentBase (const ComponentConfig &, const ComponentContext &)
 
 LoggableComponentBase (LoggableComponentBase &&)=delete
 
 LoggableComponentBase (const LoggableComponentBase &)=delete
 
 ~LoggableComponentBase () override=default
 
ComponentHealth GetComponentHealth () const override
 
void OnLoadingCancelled () override
 
void OnAllComponentsLoaded () override
 
void OnAllComponentsAreStopping () override
 

Additional Inherited Members

- Static Public Member Functions inherited from server::handlers::HttpHandlerBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from server::handlers::HandlerBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Static Public Member Functions inherited from components::LoggableComponentBase
static yaml_config::Schema GetStaticConfigSchema ()
 
- Protected Types inherited from server::handlers::HandlerBase
using HandlerErrorCode = handlers::HandlerErrorCode
 
using InternalMessage = handlers::InternalMessage
 
using ExternalBody = handlers::ExternalBody
 
using ClientError = handlers::ClientError
 
using InternalServerError = handlers::InternalServerError
 
- Protected Member Functions inherited from server::handlers::HttpHandlerBase
void ThrowUnsupportedHttpMethod (const http::HttpRequest &request) const
 
virtual void OnRequestCompleteThrow (const http::HttpRequest &, request::RequestContext &) const
 
virtual void HandleStreamRequest (const server::http::HttpRequest &, server::request::RequestContext &, server::http::ResponseBodyStream &) const
 
virtual bool IsStreamed () const
 
virtual bool IsMethodStatisticIncluded () const
 
virtual bool NeedCheckAuth () const
 
virtual std::string GetRequestBodyForLogging (const http::HttpRequest &request, request::RequestContext &context, const std::string &request_body) const
 Override it if you need a custom request body logging.
 
virtual std::string GetResponseDataForLogging (const http::HttpRequest &request, request::RequestContext &context, const std::string &response_data) const
 Override it if you need a custom response data logging.
 
virtual void ParseRequestData (const http::HttpRequest &, request::RequestContext &) const
 
virtual std::string GetMetaType (const http::HttpRequest &) const
 

Member Function Documentation

◆ HandleHandshake()

virtual bool server::websocket::WebsocketHandlerBase::HandleHandshake ( const server::http::HttpRequest & ,
server::http::HttpResponse & ,
server::request::RequestContext &  ) const
inlinevirtual

If any code is required for handshake validation, it goes here.

Definition at line 48 of file websocket_handler.hpp.


The documentation for this class was generated from the following file: