en	Decorator

en	For programs which need to modify either the outgoing WebSocket HTTP Upgrade request, the outgoing WebSocket HTTP Upgrade response, or both, the stream supports an optional property called a ['decorator]. This is a function pointer or callable object which is invoked before the implementation sends an HTTP message. The decorator receives a modifiable reference to the message, allowing for modifications. The interface to this system uses:

en	WebSocket Decorator Interface

en	Name

en	Description

en	[link beast.ref.boost__beast__websocket__request_type `request_type`]

en	This is the type of the object passed to the decorator to represent HTTP Upgrade requests.

en	[link beast.ref.boost__beast__websocket__response_type `response_type`]

en	This is the type of the object passed to the decorator to represent HTTP Upgrade response.

en	[link beast.ref.boost__beast__websocket__stream_base__decorator `stream_base::decorator`]

en	Objects of this type are used to hold a decorator to be set on the stream using `set_option`.

en	[link beast.ref.boost__beast__websocket__stream.set_option `stream::set_option`]

en	This function is used to set a `stream_base::decorator` on the stream.

en	This declares a normal function which decorates outgoing HTTP requests:

en	When using a decorator, it must be set on the stream before any handshaking takes place. This sets the decorator on the stream, to be used for all subsequent calls to accept or handshake:

en	Alternatively, a function object may be used. Small function objects will not incur a memory allocation. The follow code declares and sets a function object as a decorator:

en	A lambda may be used in place of a named function object:

en	It also possible for a single decorator to handle both requests and responses, if it is overloaded for both types either as a generic lambda (C++14 and later) or as a class as shown here:

en	The implementation takes ownership by decay-copy of the invocable object used as the decorator. Move-only types are possible:

en	Undefined behavior results if the decorator modifies the fields