Polyphase Game Engine
Loading...
Searching...
No Matches
WebSocketHandshake.h
Go to the documentation of this file.
1#pragma once
2
3#include "PolyphaseAPI.h"
5
6// ---------------------------------------------------------------------------
7// RFC 6455 opening handshake: the HTTP/1.1 GET upgrade request and the 101
8// response parse. Used by byte transports only - message transports (WinHTTP,
9// libcurl, the browser) do the handshake themselves.
10// ---------------------------------------------------------------------------
11
12// Splits "ws://host:port/path?query". Returns false and fills outError when the
13// scheme is not ws/wss or the host is empty. Port defaults to 80 / 443.
14POLYPHASE_API bool WsParseUrl(const char* url, WsUrl& outUrl, std::string& outError);
15
16// Builds the GET upgrade request. outExpectedAccept receives the
17// Sec-WebSocket-Accept value the server must echo back.
19 const WsUrl& url,
20 const std::vector<std::string>& protocols,
21 const std::vector<std::pair<std::string, std::string> >& headers,
22 std::string& outExpectedAccept);
23
24enum class WsHandshakeResult : uint8_t
25{
26 NeedMoreData = 0,
27 Ok,
28 Failed
29};
30
31// Parses the server response out of an accumulating byte buffer. On Ok,
32// outConsumed is the number of bytes the header occupied - everything after it
33// is the first of the WebSocket frame stream.
35 const uint8_t* data,
36 uint32_t size,
37 const std::string& expectedAccept,
38 uint32_t& outConsumed,
39 std::string& outSelectedProtocol,
40 std::string& outError);
Export macros for Polyphase Engine symbols.
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
WsHandshakeResult
Definition WebSocketHandshake.h:25
POLYPHASE_API std::string WsBuildHandshakeRequest(const WsUrl &url, const std::vector< std::string > &protocols, const std::vector< std::pair< std::string, std::string > > &headers, std::string &outExpectedAccept)
Definition WebSocketHandshake.cpp:163
POLYPHASE_API bool WsParseUrl(const char *url, WsUrl &outUrl, std::string &outError)
Definition WebSocketHandshake.cpp:43
POLYPHASE_API WsHandshakeResult WsParseHandshakeResponse(const uint8_t *data, uint32_t size, const std::string &expectedAccept, uint32_t &outConsumed, std::string &outSelectedProtocol, std::string &outError)
Definition WebSocketHandshake.cpp:241
Definition WebSocketTypes.h:52