WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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::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

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

Constructor.

Parameters
reqHttpParser for request

Member Function Documentation

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
bool wpi::WebSocketServerHelper::IsWebsocket ( ) const
inline

Get whether or not this was a websocket upgrade.

Only valid during and after the upgrade event.

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.

Member Data Documentation

sig::Signal wpi::WebSocketServerHelper::upgrade

Upgrade event.

Call Accept() to accept the upgrade.


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