userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
websocket_handler.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/server/handlers/websocket_handler.hpp
4
/// @brief @copybrief server::handlers::WebsocketHandlerBase
5
6
#
include
<
userver
/
components
/
component_config
.
hpp
>
7
#
include
<
userver
/
components
/
component_context
.
hpp
>
8
#
include
<
userver
/
server
/
handlers
/
http_handler_base
.
hpp
>
9
#
include
<
userver
/
websocket
/
connection
.
hpp
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
server::
handlers
{
14
15
/// @ingroup userver_components userver_http_handlers userver_base_classes
16
///
17
/// @brief Base class for WebSocket handler
18
///
19
/// ## Static options of server::websocket::WebsocketHandlerBase :
20
/// @include{doc} scripts/docs/en/components_schema/core/src/server/handlers/websocket_handler.md
21
///
22
/// Options inherited from @ref server::handlers::HttpHandlerBase :
23
/// @include{doc} scripts/docs/en/components_schema/core/src/server/handlers/http_handler_base.md
24
///
25
/// Options inherited from @ref server::handlers::HandlerBase :
26
/// @include{doc} scripts/docs/en/components_schema/core/src/server/handlers/handler_base.md
27
///
28
/// Options inherited from @ref components::ComponentBase :
29
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
30
///
31
/// ## Example usage:
32
///
33
/// @snippet samples/websocket_service/main.cpp Websocket service sample - component
34
class
WebsocketHandlerBase
:
public
server::
handlers
::
HttpHandlerBase
{
35
public
:
36
WebsocketHandlerBase(
const
components
::ComponentConfig&,
const
components
::ComponentContext&);
37
38
/// @brief Websocket handler code belongs here.
39
virtual
void
Handle
(websocket::
WebSocketConnection
& websocket, server::
request
::RequestContext&)
const
= 0;
40
41
/// @brief If any code is required for handshake validation,
42
/// it goes here.
43
/// @return \a true to accept the WebSocket connection, \a false to reject
44
/// it (handshake will be aborted and connection will not be established).
45
virtual
bool
HandleHandshake
(server::
http
::HttpRequest&, server::
request
::RequestContext&)
const
{
return
true
; }
46
47
/// @cond
48
void
WriteMetrics(
utils
::
statistics
::Writer& writer)
const
;
49
50
static
yaml_config::Schema GetStaticConfigSchema();
51
/// @endcond
52
53
bool
IsWebsocketRequest(
const
server::
http
::HttpRequest& request)
const
;
54
55
/// @brief If \a request isn't a websocket request the function handles a
56
/// request.
57
virtual
std::string
HandleNonWebsocketRequest
(
58
server::
http
::HttpRequest& request,
59
server::
request
::RequestContext& context
60
)
const
;
61
62
/// @brief If \a request is a websocket request, performs handshake and upgrade.
63
virtual
void
HandleWebsocketRequest
(server::
http
::HttpRequest& request, server::
request
::RequestContext& context)
64
const
;
65
66
protected
:
67
std::string
HandleRequest
(server::
http
::HttpRequest& request, server::
request
::RequestContext& context)
68
const
override
;
69
70
private
:
71
websocket::Config config_;
72
mutable
websocket::Statistics stats_;
73
};
74
75
}
// namespace server::handlers
76
77
USERVER_NAMESPACE_END
userver
server
handlers
websocket_handler.hpp
Generated on
for userver by
Doxygen
1.17.0