WPILibC++ 2023.4.3
|
A server-side HTTP connection that also accepts WebSocket upgrades. More...
#include <wpinet/HttpWebSocketServerConnection.h>
Public Member Functions | |
HttpWebSocketServerConnection (std::shared_ptr< uv::Stream > stream, std::span< const std::string_view > protocols) | |
Constructor. More... | |
HttpWebSocketServerConnection (std::shared_ptr< uv::Stream > stream, std::initializer_list< std::string_view > protocols) | |
Constructor. More... | |
Public Member Functions inherited from wpi::HttpServerConnection | |
HttpServerConnection (std::shared_ptr< uv::Stream > stream) | |
virtual | ~HttpServerConnection ()=default |
Protected Member Functions | |
virtual bool | IsValidWsUpgrade (std::string_view protocol) |
Check that an incoming WebSocket upgrade is okay. More... | |
virtual void | ProcessWsUpgrade ()=0 |
Process an incoming WebSocket upgrade. More... | |
Protected Member Functions inherited from wpi::HttpServerConnection | |
virtual void | ProcessRequest ()=0 |
Process an incoming HTTP request. More... | |
virtual void | BuildCommonHeaders (raw_ostream &os) |
Build common response headers. More... | |
virtual void | BuildHeader (raw_ostream &os, int code, std::string_view codeText, std::string_view contentType, uint64_t contentLength, std::string_view extra={}) |
Build HTTP response header, along with other header information like mimetype. More... | |
void | SendData (std::span< const uv::Buffer > bufs, bool closeAfter=false) |
Send data to client. More... | |
virtual void | SendResponse (int code, std::string_view codeText, std::string_view contentType, std::string_view content, std::string_view extraHeader={}) |
Send HTTP response, along with other header information like mimetype. More... | |
virtual void | SendStaticResponse (int code, std::string_view codeText, std::string_view contentType, std::string_view content, bool gzipped, std::string_view extraHeader={}) |
Send HTTP response from static data, along with other header information like mimetype. More... | |
virtual void | SendError (int code, std::string_view message={}) |
Send error header and message. More... | |
Protected Attributes | |
WebSocket * | m_websocket = nullptr |
WebSocket connection; not valid until ProcessWsUpgrade is called. More... | |
Protected Attributes inherited from wpi::HttpServerConnection | |
HttpParser | m_request {HttpParser::kRequest} |
The HTTP request. More... | |
bool | m_keepAlive = false |
Whether the connection should be kept alive. More... | |
bool | m_acceptGzip = false |
If gzip is an acceptable encoding for responses. More... | |
uv::Stream & | m_stream |
The underlying stream for the connection. More... | |
sig::ScopedConnection | m_dataConn |
The header reader connection. More... | |
sig::ScopedConnection | m_endConn |
The end stream connection. More... | |
sig::Connection | m_messageCompleteConn |
The message complete connection. More... | |
A server-side HTTP connection that also accepts WebSocket upgrades.
Derived | derived class for std::enable_shared_from_this. |
wpi::HttpWebSocketServerConnection< Derived >::HttpWebSocketServerConnection | ( | std::shared_ptr< uv::Stream > | stream, |
std::span< const std::string_view > | protocols | ||
) |
Constructor.
stream | network stream |
protocols | Acceptable subprotocols |
|
inline |
Constructor.
stream | network stream |
protocols | Acceptable subprotocols |
|
inlineprotectedvirtual |
Check that an incoming WebSocket upgrade is okay.
This is called prior to accepting the upgrade (so prior to ProcessWsUpgrade()).
The implementation should check other headers and return true if the WebSocket connection should be accepted.
protocol | negotiated subprotocol |
|
protectedpure virtual |
Process an incoming WebSocket upgrade.
This is called after the header reader has been disconnected and the websocket has been accepted.
The implementation should set up appropriate callbacks on the websocket object to continue communication.
|
protected |
WebSocket connection; not valid until ProcessWsUpgrade is called.