forked from boostorg/beast
New buffer sequence classes are provided to allow full
control over the serialization of chunk-encoded message
payloads:
* chunk_header
A ConstBufferSequence representing the chunk header.
It includes a hexadecimal-encoded size, an optional
set of chunk extensions, and the trailing CRLF
required to denote the end of the chunk header.
This allows the caller to manually serialize the chunk
body in one or more calls to a stream output function.
The caller must also output an object of type `chunk_crlf`
to the stream to indicate the end of the chunk body.
* chunk_crlf
A small ConstBufferSequence that simply represents
the two character sequence "\r\n" (CRLF). This is needed
for the case where the caller wants to output a chunk
body as a series of buffers (i.e. "chunking a chunk").
* chunk_body
A ConstBufferSequence representing a complete chunk.
This includes the size, an optional set of chunk extensions,
a caller provided buffer containing the body, and the
required CRLF that follows.
* chunk_final
A ConstBufferSequence representing a final chunk. It
includes an optional set of caller-provided field trailers
* chunk_extensions
A container for building a set of chunk extensions to use
during serialization. The use of the container is optional,
callers may provide their own buffer containing a correctly
formatted set of chunk extensions, or they may use their
own convenience container which meets the requirements.
The basic_fields container is modified to allow construction
outside the context of a message. The container can be used
to provide trailers to `chunk_final`.
Actions Required:
* Remove references to ChunkDecorators. Use the new chunk-encoding
buffer sequences to manually produce a chunked payload body in
the case where control over the chunk-extensions and/or trailers
is required.
118 lines
4.2 KiB
Plaintext
118 lines
4.2 KiB
Plaintext
[/
|
|
Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
]
|
|
|
|
[section:BodyReader BodyReader]
|
|
|
|
A [*BodyReader] provides an online algorithm to obtain a sequence of zero
|
|
or more buffers from a body during serialization. The implementation creates
|
|
an instance of this type when needed, and calls into it one or more times to
|
|
retrieve buffers holding body octets. The interface of [*BodyReader] is
|
|
intended to obtain buffers for these scenarios:
|
|
|
|
* A body that does not entirely fit in memory.
|
|
* A body produced incrementally from coroutine output.
|
|
* A body represented by zero or more buffers already in memory.
|
|
* A body whose size is not known ahead of time.
|
|
* Body data generated dynamically from other threads.
|
|
* Body data computed algorithmically.
|
|
|
|
In this table:
|
|
|
|
* `X` denotes a type meeting the requirements of [*BodyReader].
|
|
|
|
* `B` denotes a __Body__ where
|
|
`std::is_same<X, B::reader>::value == true`.
|
|
|
|
* `a` denotes a value of type `X`.
|
|
|
|
* `m` denotes a possibly const value of type `message&` where
|
|
`std::is_same<decltype(m.body), Body::value_type>:value == true`.
|
|
|
|
* `ec` is a value of type [link beast.ref.beast__error_code `error_code&`].
|
|
|
|
* `R<T>` is the type `boost::optional<std::pair<T, bool>>`.
|
|
|
|
[heading Associated Types]
|
|
|
|
* __Body__
|
|
|
|
* [link beast.ref.beast__http__is_body_reader `is_body_reader`]
|
|
|
|
[heading BodyReader requirements]
|
|
[table Valid Expressions
|
|
[[Expression] [Type] [Semantics, Pre/Post-conditions]]
|
|
[
|
|
[`X::const_buffers_type`]
|
|
[]
|
|
[
|
|
A type which meets the requirements of __ConstBufferSequence__.
|
|
This is the type of buffer returned by `X::get`.
|
|
]
|
|
][
|
|
[`X(m);`]
|
|
[]
|
|
[
|
|
Constructible from `m`. The lifetime of `m` is guaranteed
|
|
to end no earlier than after the `X` is destroyed.
|
|
The reader shall not access the contents of `m` before the
|
|
first call to `init`, permitting lazy construction of the
|
|
message.
|
|
|
|
The constructor may optionally require that `m` is const, which
|
|
has these consequences:
|
|
|
|
* If `X` requires that `m` is a const reference, then serializers
|
|
constructed for messages with this body type will also require a
|
|
const reference to a message, otherwise:
|
|
|
|
* If `X` requires that `m` is a non-const reference, then serializers
|
|
constructed for messages with this body type will aso require
|
|
a non-const reference to a message.
|
|
]
|
|
][
|
|
[`a.init(ec)`]
|
|
[]
|
|
[
|
|
Called once to fully initialize the object before any calls to
|
|
`get`. The message body becomes valid before entering this function,
|
|
and remains valid until the reader is destroyed.
|
|
The function will ensure that `!ec` is `true` if there was
|
|
no error or set to the appropriate error code if there was one.
|
|
]
|
|
][
|
|
[`a.get(ec)`]
|
|
[`R<X::const_buffers_type>`]
|
|
[
|
|
Called one or more times after `init` succeeds. This function
|
|
returns `boost::none` if all buffers representing the body have
|
|
been returned in previous calls or if it sets `ec` to indicate an
|
|
error. Otherwise, if there are buffers remaining the function
|
|
should return a pair with the first element containing a non-zero
|
|
length buffer sequence representing the next set of octets in
|
|
the body, while the second element is a `bool` meaning `true`
|
|
if there may be additional buffers returned on a subsequent call,
|
|
or `false` if the buffer returned on this call is the last
|
|
buffer representing the body.
|
|
The function will ensure that `!ec` is `true` if there was
|
|
no error or set to the appropriate error code if there was one.
|
|
]
|
|
]
|
|
]
|
|
|
|
[heading Exemplar]
|
|
|
|
[concept_BodyReader]
|
|
|
|
[heading Models]
|
|
|
|
* [link beast.ref.beast__http__basic_dynamic_body.reader `basic_dynamic_body::reader`]
|
|
* [link beast.ref.beast__http__basic_file_body__reader `basic_file_body::reader`]
|
|
* [link beast.ref.beast__http__basic_string_body.reader `basic_string_body::reader`]
|
|
* [link beast.ref.beast__http__empty_body.reader `empty_body::reader`]
|
|
|
|
[endsect]
|