28#ifndef WEBSOCKETPP_PROCESSOR_HPP
29#define WEBSOCKETPP_PROCESSOR_HPP
67template <
typename request_type>
71 std::string
const & upgrade_header =
r.get_header(
"Upgrade");
73 if (ci_find_substr(upgrade_header, constants::upgrade_token,
74 sizeof(constants::upgrade_token)-1) == upgrade_header.end())
79 std::string
const & con_header =
r.get_header(
"Connection");
81 if (ci_find_substr(con_header, constants::connection_token,
82 sizeof(constants::connection_token)-1) == con_header.end())
106template <
typename request_type>
112 if (
r.get_header(
"Sec-WebSocket-Version").empty()) {
117 std::istringstream ss(
r.get_header(
"Sec-WebSocket-Version"));
119 if ((ss >> version).fail()) {
135template <
typename request_type>
137 std::string h = request.get_header(
"Host");
139 size_t last_colon = h.rfind(
":");
140 size_t last_sbrace = h.rfind(
"]");
146 if (last_colon == std::string::npos ||
147 (last_sbrace != std::string::npos && last_sbrace > last_colon))
149 return lib::make_shared<uri>(scheme, h, request.get_uri());
151 return lib::make_shared<uri>(scheme,
152 h.substr(0,last_colon),
153 h.substr(last_colon+1),
159template <
typename config>
265 std::string
const & subprotocol,
response_type& res)
const = 0;
274 uri_ptr uri, std::vector<std::string>
const & subprotocols)
const = 0;
301 std::vector<std::string> & subprotocol_list) = 0;
397 std::string
const & reason,
message_ptr out)
const = 0;
WebSocket protocol processor abstract base class.
virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out)=0
Prepare a data message for writing.
virtual size_t get_bytes_needed() const
virtual size_t consume(uint8_t *buf, size_t len, lib::error_code &ec)=0
process new websocket connection bytes
virtual lib::error_code prepare_close(close::status::value code, std::string const &reason, message_ptr out) const =0
Prepare a close frame.
virtual err_str_pair negotiate_extensions(response_type const &)
Initializes extensions based on the Sec-WebSocket-Extensions header.
virtual int get_version() const =0
Get the protocol version of this processor.
virtual std::string get_raw(response_type const &request) const =0
Given a completed response, get the raw bytes to put on the wire.
virtual bool ready() const =0
Checks if there is a message ready.
virtual lib::error_code process_handshake(request_type const &req, std::string const &subprotocol, response_type &res) const =0
Calculate the appropriate response for this websocket request.
processor(bool secure, bool p_is_server)
size_t m_max_message_size
config::request_type request_type
virtual lib::error_code validate_handshake(request_type const &request) const =0
validate a WebSocket handshake request for this version
virtual uri_ptr get_uri(request_type const &request) const =0
Extracts client uri from a handshake request.
config::message_type::ptr message_ptr
virtual err_str_pair negotiate_extensions(request_type const &)
Initializes extensions based on the Sec-WebSocket-Extensions header.
virtual bool has_permessage_compress() const
Returns whether or not the permessage_compress extension is implemented.
virtual lib::error_code prepare_ping(std::string const &in, message_ptr out) const =0
Prepare a ping frame.
virtual lib::error_code validate_server_handshake_response(request_type const &req, response_type &res) const =0
Validate the server's response to an outgoing handshake request.
virtual lib::error_code client_handshake_request(request_type &req, uri_ptr uri, std::vector< std::string > const &subprotocols) const =0
Fill in an HTTP request for an outgoing connection handshake.
virtual lib::error_code extract_subprotocols(const request_type &req, std::vector< std::string > &subprotocol_list)=0
Extracts requested subprotocols from a handshake request.
virtual bool get_error() const =0
Tests whether the processor is in a fatal error state.
config::response_type response_type
void set_max_message_size(size_t new_value)
Set maximum message size.
virtual std::string const & get_origin(request_type const &request) const =0
Return the value of the header containing the CORS origin.
size_t get_max_message_size() const
Get maximum message size.
std::pair< lib::error_code, std::string > err_str_pair
virtual message_ptr get_message()=0
Retrieves the most recently processed message.
virtual lib::error_code prepare_pong(std::string const &in, message_ptr out) const =0
Prepare a pong frame.
uint16_t value
The type of a close code value.
int get_websocket_version(request_type &r)
Extract the version from a WebSocket handshake request.
uri_ptr get_uri_from_host(request_type &request, std::string scheme)
Extract a URI ptr from the host header of the request.
bool is_websocket_handshake(request_type &r)
Determine whether or not a generic HTTP request is a WebSocket handshake.
T::const_iterator ci_find_substr(T const &haystack, T const &needle, std::locale const &loc=std::locale())
Find substring (case insensitive)
Namespace for the WebSocket++ project.
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.