en	Parser Stream Operations

en	Non-trivial algorithms need to do more than receive entire messages at once, such as:

en	* Receive the header first and body later.

en	* Receive a large body using a fixed-size buffer.

en	* Receive a message incrementally: bounded work in each I/O cycle.

en	* Defer the commitment to a __Body__ type until after reading the header.

en	These types of operations require callers to manage the lifetime of associated state, by constructing a class derived from __basic_parser__. Beast comes with the derived instance __parser__ which creates complete __message__ objects using the __basic_fields__ Fields container.

en	Parser

en	Name

en	Description

en	__parser__

en	/// An HTTP/1 parser for producing a message. template< bool isRequest, // `true` to parse an HTTP request class Body, // The Body type for the resulting message class Allocator = std::allocator<char>> // The type of allocator for the header class parser : public basic_parser<...>;

en	[link beast.ref.boost__beast__http__request_parser `request_parser`]

en	/// An HTTP/1 parser for producing a request message. template<class Body, class Allocator = std::allocator<char>> using request_parser = parser<true, Body, Allocator>;

en	[link beast.ref.boost__beast__http__response_parser `response_parser`]

en	/// An HTTP/1 parser for producing a response message. template<class Body, class Allocator = std::allocator<char>> using response_parser = parser<false, Body, Allocator>;

en	The __basic_parser__ and classes derived from it handle octet streams

en	The stream operations which work on parsers are:

en	Parser Stream Operations

en	Name

en	Description

en	[link beast.ref.boost__beast__http__read.overload1 [*read]]

en	Read everything into a parser from a __SyncReadStream__.

en	[link beast.ref.boost__beast__http__async_read.overload1 [*async_read]]

en	Read everything into a parser asynchronously from an __AsyncReadStream__.

en	[link beast.ref.boost__beast__http__read_header.overload1 [*read_header]]

en	Read only the header octets into a parser from a __SyncReadStream__.

en	[link beast.ref.boost__beast__http__async_read_header [*async_read_header]]

en	Read only the header octets into a parser asynchronously from an __AsyncReadStream__.

en	[link beast.ref.boost__beast__http__read_some.overload1 [*read_some]]

en	Read some octets into a parser from a __SyncReadStream__.

en	[link beast.ref.boost__beast__http__async_read_some [*async_read_some]]

en	Read some octets into a parser asynchronously from an __AsyncReadStream__.

en	As with message stream operations, parser stream operations require a persisted __DynamicBuffer__ for holding unused octets from the stream. The basic parser implementation is optimized for the case where this dynamic buffer stores its input sequence in a single contiguous memory buffer. It is advised to use an instance of __flat_buffer__, __flat_static_buffer__, or __flat_static_buffer_base__ for this purpose, although a user defined instance of __DynamicBuffer__ which produces input sequences of length one is also suitable.

en	The parser contains a message constructed internally. Arguments passed to the parser's constructor are forwarded into the message container. The caller can access the message inside the parser by calling [link beast.ref.boost__beast__http__parser.get `parser::get`]. If the `Fields` and `Body` types are [*MoveConstructible], the caller can take ownership of the message by calling [link beast.ref.boost__beast__http__parser.release `parser::release`]. In this example we read an HTTP response with a string body using a parser, then print the response:

en	Incremental Read __example__

en	This function uses [link beast.ref.boost__beast__http__buffer_body `buffer_body`] and parser stream operations to read a message body progressively using a small, fixed-size buffer:

en	Reading large response body __example__

en	This example presents how to increase the default limit of the response body size, thus the content larger than the default 8MB can be read.