Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

websocket::is_upgrade

Returns true if the specified HTTP request is a WebSocket Upgrade.

Synopsis

Defined in header <boost/beast/websocket/rfc6455.hpp>

template<
    class Allocator>
bool
is_upgrade(
    beast::http::header< true, http::basic_fields< Allocator >> const& req);
Description

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.

Example
void handle_connection(boost::asio::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);
    }
}
Parameters

Name

Description

req

The HTTP Request object to check.

Return Value

true if the request is a WebSocket Upgrade.

Convenience header <boost/beast/websocket.hpp>


PrevUpHomeNext