C++ Actor Framework 1.0.0
|
Wraps state and algorithms for the WebSocket client handshake as defined in RFC 6455. More...
#include <handshake.hpp>
Public Types | |
using | key_type = std::array<std::byte, 16> |
Public Member Functions | |
handshake (const handshake &)=default | |
handshake (handshake &&) noexcept=default | |
handshake & | operator= (const handshake &)=default |
handshake & | operator= (handshake &&) noexcept=default |
const auto & | key () const noexcept |
Returns the 16-byte key for the opening handshake. | |
void | key (key_type new_key) noexcept |
Sets the 16-byte key for the opening handshake. | |
bool | assign_key (std::string_view base64_key) |
Tries to assign a key from base64 input. | |
std::string | response_key () const |
Returns the key for the response message, i.e., what the server puts into the HTTP field Sec-WebSocket-Accept . | |
const auto & | fields () const noexcept |
Returns all configured header fields, except the key. | |
bool | has_valid_key () const noexcept |
Checks whether at least one bit in the key is one. | |
bool | has_mandatory_fields () const noexcept |
Checks whether all mandatory fields were provided by the user. | |
void | randomize_key () |
Fills the key with pseudo-random numbers generated by std::minstd_rand with a seed chosen from std::random_device . | |
void | randomize_key (unsigned seed) |
Fills the key with pseudo-random numbers generated by std::minstd_rand , initialized with seed . | |
void | endpoint (std::string value) |
Sets a value for the mandatory WebSocket endpoint, i.e., the Request-URI component of the GET method according to RFC 2616. | |
bool | has_endpoint () const noexcept |
Checks whether the handshake has an endpoint defined. | |
void | host (std::string value) |
Sets a value for the mandatory Host field. | |
bool | has_host () const noexcept |
Checks whether the handshake has an host defined. | |
void | origin (std::string value) |
Sets a value for the optional Origin field. | |
void | protocols (std::string value) |
Sets a value for the optional Sec-WebSocket-Protocol field. | |
void | extensions (std::string value) |
Sets a value for the optional Sec-WebSocket-Extensions field. | |
void | write_http_1_request (byte_buffer &buf) const |
Writes the HTTP 1.1 request message to buf . | |
void | write_http_1_response (byte_buffer &buf) const |
Writes the HTTP 1.1 response message to buf . | |
void | write_response (http::lower_layer::server *down) const |
Writes the HTTP response message to down . | |
bool | is_valid_http_1_response (std::string_view http_response) const |
Checks whether the http_response contains a HTTP 1.1 response to the generated HTTP GET request. | |
Static Public Attributes | |
static constexpr uint32_t | max_http_size = 2048 |
Maximum size for HTTP request and response messages. | |
Wraps state and algorithms for the WebSocket client handshake as defined in RFC 6455.
void caf::net::web_socket::handshake::endpoint | ( | std::string | value | ) |
Sets a value for the mandatory WebSocket endpoint, i.e., the Request-URI component of the GET method according to RFC 2616.
value | Identifies the endpoint that should handle the request. |
void caf::net::web_socket::handshake::extensions | ( | std::string | value | ) |
Sets a value for the optional Sec-WebSocket-Extensions
field.
value | A comma-separated list of values indicating which extensions the client would like to speak, ordered by preference. |
|
nodiscardnoexcept |
Checks whether at least one bit in the key is one.
A default constructed header object fills the key with zeros.
void caf::net::web_socket::handshake::host | ( | std::string | value | ) |
Sets a value for the mandatory Host
field.
value | The Internet host and port number of the resource being requested, as obtained from the original URI given by the user or referring resource. |
bool caf::net::web_socket::handshake::is_valid_http_1_response | ( | std::string_view | http_response | ) | const |
Checks whether the http_response
contains a HTTP 1.1 response to the generated HTTP GET request.
A valid response contains:
Upgrade
field with the value websocket
.Connection
field with the value Upgrade
.Sec-WebSocket-Accept
field with the value response_key()
. void caf::net::web_socket::handshake::origin | ( | std::string | value | ) |
Sets a value for the optional Origin
field.
value | Indicates where the GET request originates from. Usually only sent by browser clients. |
void caf::net::web_socket::handshake::protocols | ( | std::string | value | ) |
Sets a value for the optional Sec-WebSocket-Protocol
field.
value | A comma-separated list of values indicating which protocols the client would like to speak, ordered by preference. |
void caf::net::web_socket::handshake::write_http_1_request | ( | byte_buffer & | buf | ) | const |
Writes the HTTP 1.1 request message to buf
.
has_mandatory_fields()
void caf::net::web_socket::handshake::write_http_1_response | ( | byte_buffer & | buf | ) | const |
Writes the HTTP 1.1 response message to buf
.
has_valid_key()
void caf::net::web_socket::handshake::write_response | ( | http::lower_layer::server * | down | ) | const |
Writes the HTTP response message to down
.
has_valid_key()
|
staticconstexpr |
Maximum size for HTTP request and response messages.
A handshake should usually fit into 200-300 Bytes, so 2KB is more than enough.