...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Returns true
if the specified
HTTP request is a WebSocket Upgrade.
Defined in header <boost/beast/websocket/rfc6455.hpp>
template< class Allocator> bool is_upgrade( beast::http::header< true, http::basic_fields< Allocator > > const& req);
This function returns true
when
the passed HTTP Request indicates a WebSocket Upgrade. It does not validate
the contents of the fields: it just trivially accepts requests which could
only possibly be a valid or invalid WebSocket Upgrade message.
Callers who wish to manually read HTTP requests in their server implementation
can use this function to determine if the request should be routed to an
instance of websocket::stream
.
void handle_connection(net::ip::tcp::socket& sock) { boost::beast::flat_buffer buffer; boost::beast::http::request<boost::beast::http::string_body> req; boost::beast::http::read(sock, buffer, req); if (boost::beast::websocket::is_upgrade(req)) { boost::beast::websocket::stream< decltype (sock)> ws{std::move(sock)}; ws.accept(req); } }
Name |
Description |
---|---|
|
The HTTP Request object to check. |
true
if the request is a WebSocket
Upgrade.