Beast Logo

PrevUpHomeNext

websocket::decorate

HTTP decorator option.

using decorate = implementation-defined;

The decorator transforms the HTTP requests and responses used when requesting or responding to the WebSocket Upgrade. This may be used to set or change header fields. For example to set the Server or User-Agent fields. The default setting applies no transformation to the HTTP message.

The context in which the decorator is called depends on the type of operation performed:

The default setting is no decorator.

Remarks

Objects of this type are used with beast::websocket::stream::set_option.

Example

Setting the decorator.

struct identity
{
    template<bool isRequest, class Body, class Fields>
    void
    operator()(http::message<isRequest, Body, Fields>& m)
    {
        if(isRequest)
            m.fields.replace("User-Agent", "MyClient");
        else
            m.fields.replace("Server", "MyServer");
    }
};
...
websocket::stream<ip::tcp::socket> ws(ios);
ws.set_option(decorate(identity{}));
Requirements

Header: beast/websocket/option.hpp

Convenience header: beast/websocket.hpp


PrevUpHomeNext