WPILibC++ 2024.3.2
wpi::WebSocketServerHelper Class Reference

WebSocket HTTP server helper. More...

#include <wpinet/WebSocketServer.h>

Public Member Functions

 WebSocketServerHelper (HttpParser &req)
 Constructor. More...
 
bool IsWebsocket () const
 Get whether or not this was a websocket upgrade. More...
 
std::pair< bool, std::string_viewMatchProtocol (std::span< const std::string_view > protocols)
 Try to find a match to the list of sub-protocols provided by the client. More...
 
std::pair< bool, std::string_viewMatchProtocol (std::initializer_list< std::string_view > protocols)
 Try to find a match to the list of sub-protocols provided by the client. More...
 
std::shared_ptr< WebSocketAccept (uv::Stream &stream, std::string_view protocol={})
 Accept the upgrade. More...
 
bool IsUpgrade () const
 

Public Attributes

sig::Signal upgrade
 Upgrade event. More...
 

Detailed Description

WebSocket HTTP server helper.

Handles websocket-specific headers. User must provide the HttpParser.

Constructor & Destructor Documentation

◆ WebSocketServerHelper()

wpi::WebSocketServerHelper::WebSocketServerHelper ( HttpParser req)
explicit

Constructor.

Parameters
reqHttpParser for request

Member Function Documentation

◆ Accept()

std::shared_ptr< WebSocket > wpi::WebSocketServerHelper::Accept ( uv::Stream stream,
std::string_view  protocol = {} 
)
inline

Accept the upgrade.

Disconnect other readers (such as the HttpParser reader) before calling this. See also WebSocket::CreateServer().

Parameters
streamConnection stream
protocolThe subprotocol to send to the client

◆ IsUpgrade()

bool wpi::WebSocketServerHelper::IsUpgrade ( ) const
inline

◆ IsWebsocket()

bool wpi::WebSocketServerHelper::IsWebsocket ( ) const
inline

Get whether or not this was a websocket upgrade.

Only valid during and after the upgrade event.

◆ MatchProtocol() [1/2]

std::pair< bool, std::string_view > wpi::WebSocketServerHelper::MatchProtocol ( std::initializer_list< std::string_view protocols)
inline

Try to find a match to the list of sub-protocols provided by the client.

The list is priority ordered, so the first match wins. Only valid during and after the upgrade event.

Parameters
protocolsAcceptable protocols
Returns
Pair; first item is true if a match was made, false if not. Second item is the matched protocol if a match was made, otherwise is empty.

◆ MatchProtocol() [2/2]

std::pair< bool, std::string_view > wpi::WebSocketServerHelper::MatchProtocol ( std::span< const std::string_view protocols)

Try to find a match to the list of sub-protocols provided by the client.

The list is priority ordered, so the first match wins. Only valid during and after the upgrade event.

Parameters
protocolsAcceptable protocols
Returns
Pair; first item is true if a match was made, false if not. Second item is the matched protocol if a match was made, otherwise is empty.

Member Data Documentation

◆ upgrade

sig::Signal wpi::WebSocketServerHelper::upgrade

Upgrade event.

Call Accept() to accept the upgrade.


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