Beast Logo

PrevUpHomeNext

http::with_body

Create a new parser from a fields parser.

template<
    class Body,
    bool isRequest,
    class Fields,
    class... Args>
parser_v1< isRequest, Body, Fields >
with_body(
    header_parser_v1< isRequest, Fields >& parser,
    Args&&... args);

Associates a Body type with a fields parser, and returns a new parser which parses a complete message object containing the original message fields and a new body of the specified body type.

This function allows HTTP messages to be parsed in two stages. First, the fields are parsed and control is returned. Then, the caller can choose at run-time, the type of Body to associate with the message. And finally, complete the parse in a second call.

Parameters

parser

The fields parser to construct from. Ownership of the message fields in the fields parser is transferred as if by call to header_parser_v1::release.

args

Forwarded to the body constructor of the message in the new parser.

Return Value

A parser for a message with the specified Body type.

Example
headers_parser<true, fields> ph;
...
auto p = with_body<string_body>(ph);
...
message<true, string_body, fields> m = p.release();
Requirements

Header: beast/http/parser_v1.hpp

Convenience header: beast/http.hpp


PrevUpHomeNext