28 #ifndef WEBSOCKETPP_PROCESSOR_HPP 29 #define WEBSOCKETPP_PROCESSOR_HPP 67 template <
typename request_type>
71 std::string
const & upgrade_header = r.get_header(
"Upgrade");
79 std::string
const & con_header = r.get_header(
"Connection");
106 template <
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()) {
135 template <
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),
159 template <
typename config>
265 std::string
const & subprotocol, response_type& res)
const = 0;
274 uri_ptr uri, std::vector<std::string>
const & subprotocols)
const = 0;
283 const & req, response_type & res)
const = 0;
286 virtual std::string
get_raw(response_type
const & request)
const = 0;
289 virtual std::string
const &
get_origin(request_type
const & request)
const = 0;
301 std::vector<std::string> & subprotocol_list) = 0;
316 virtual size_t consume(uint8_t *buf,
size_t len, lib::error_code & ec) = 0;
327 virtual bool ready()
const = 0;
369 virtual lib::error_code
prepare_ping(std::string
const & in, message_ptr out)
const 381 virtual lib::error_code
prepare_pong(std::string
const & in, message_ptr out)
const 397 std::string
const & reason, message_ptr out)
const = 0;
407 #endif //WEBSOCKETPP_PROCESSOR_HPP static char const connection_token[]
virtual err_str_pair negotiate_extensions(response_type const &)
Initializes extensions based on the Sec-WebSocket-Extensions header.
uint16_t value
The type of a close code value.
size_t get_max_message_size() const
Get maximum message size.
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.
void set_max_message_size(size_t new_value)
Set maximum message size.
processor(bool secure, bool p_is_server)
WebSocket protocol processor abstract base class.
int get_websocket_version(request_type &r)
Extract the version from a WebSocket handshake request.
virtual lib::error_code validate_handshake(request_type const &request) const =0
validate a WebSocket handshake request for this version
config::request_type request_type
virtual std::string const & get_origin(request_type const &request) const =0
Return the value of the header containing the CORS origin.
virtual bool has_permessage_compress() const
Returns whether or not the permessage_compress extension is implemented.
virtual lib::error_code prepare_pong(std::string const &in, message_ptr out) const =0
Prepare a pong frame.
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 lib::error_code prepare_ping(std::string const &in, message_ptr out) const =0
Prepare a ping frame.
static char const upgrade_token[]
virtual bool get_error() const =0
Tests whether the processor is in a fatal error state.
A package of types and methods for manipulating WebSocket close codes.
Stores, parses, and manipulates HTTP responses.
virtual size_t consume(uint8_t *buf, size_t len, lib::error_code &ec)=0
process new websocket connection bytes
virtual int get_version() const =0
Get the protocol version of this processor.
virtual lib::error_code prepare_data_frame(message_ptr in, message_ptr out)=0
Prepare a data message for writing.
virtual message_ptr get_message()=0
Retrieves the most recently processed message.
lib::shared_ptr< message > ptr
virtual uri_ptr get_uri(request_type const &request) const =0
Extracts client uri from a 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.
Namespace for the WebSocket++ project.
virtual err_str_pair negotiate_extensions(request_type const &)
Initializes extensions based on the Sec-WebSocket-Extensions header.
virtual bool ready() const =0
Checks if there is a message ready.
std::pair< lib::error_code, std::string > err_str_pair
size_t m_max_message_size
config::response_type response_type
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
virtual lib::error_code prepare_close(close::status::value code, std::string const &reason, message_ptr out) const =0
Prepare a close frame.
virtual size_t get_bytes_needed() const
Retrieves the number of bytes presently needed by the processor This value may be used as a hint to t...
Stores, parses, and manipulates HTTP requests.
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 process_handshake(request_type const &req, std::string const &subprotocol, response_type &res) const =0
Calculate the appropriate response for this websocket request.
config::message_type::ptr message_ptr
virtual lib::error_code extract_subprotocols(const request_type &req, std::vector< std::string > &subprotocol_list)=0
Extracts requested subprotocols from a handshake request.
T::const_iterator ci_find_substr(T const &haystack, T const &needle, std::locale const &loc=std::locale())
Find substring (case insensitive)