WPILibC++  2020.3.2-60-g3011ebe
wpi::WebSocketServerHelper Class Reference

WebSocket HTTP server helper. More...

#include <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, StringRefMatchProtocol (ArrayRef< StringRef > protocols)
 Try to find a match to the list of sub-protocols provided by the client. More...
 
std::pair< bool, StringRefMatchProtocol (std::initializer_list< StringRef > protocols)
 Try to find a match to the list of sub-protocols provided by the client. More...
 
std::shared_ptr< WebSocketAccept (uv::Stream &stream, StringRef protocol=StringRef{})
 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,
StringRef  protocol = StringRef{} 
)
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

◆ 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, StringRef> wpi::WebSocketServerHelper::MatchProtocol ( ArrayRef< StringRef 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.

◆ MatchProtocol() [2/2]

std::pair<bool, StringRef> wpi::WebSocketServerHelper::MatchProtocol ( std::initializer_list< StringRef 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.

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: