forked from boostorg/beast
parser is constructible from other body types
This commit is contained in:
+45
-23
@@ -44,29 +44,6 @@ synchronous version of this server action looks like this:
|
||||
|
||||
|
||||
|
||||
[section Send Child Process Output]
|
||||
|
||||
Sometimes it is necessary to send a message whose body is not conveniently
|
||||
described by a single container. For example, when implementing an HTTP relay
|
||||
function a robust implementation needs to present body buffers individually
|
||||
as they become available from the downstream host. These buffers should be
|
||||
fixed in size, otherwise creating the unnecessary and inefficient burden of
|
||||
reading the complete message body before forwarding it to the upstream host.
|
||||
|
||||
To enable these use-cases, the body type __buffer_body__ is provided. This
|
||||
body uses a caller-provided pointer and size instead of an owned container.
|
||||
To use this body, instantiate an instance of the serializer and fill in
|
||||
the pointer and size fields before calling a stream write function.
|
||||
|
||||
This example reads from a child process and sends the output back in an
|
||||
HTTP response. The output of the process is sent as it becomes available:
|
||||
|
||||
[http_sample_send_cgi_response]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[section HEAD request (Client)]
|
||||
|
||||
The
|
||||
@@ -134,6 +111,51 @@ parses an HTTP message from a `std::istream`:
|
||||
|
||||
|
||||
|
||||
[section Send Child Process Output]
|
||||
|
||||
Sometimes it is necessary to send a message whose body is not conveniently
|
||||
described by a single container. For example, when implementing an HTTP relay
|
||||
function a robust implementation needs to present body buffers individually
|
||||
as they become available from the downstream host. These buffers should be
|
||||
fixed in size, otherwise creating the unnecessary and inefficient burden of
|
||||
reading the complete message body before forwarding it to the upstream host.
|
||||
|
||||
To enable these use-cases, the body type __buffer_body__ is provided. This
|
||||
body uses a caller-provided pointer and size instead of an owned container.
|
||||
To use this body, instantiate an instance of the serializer and fill in
|
||||
the pointer and size fields before calling a stream write function.
|
||||
|
||||
This example reads from a child process and sends the output back in an
|
||||
HTTP response. The output of the process is sent as it becomes available:
|
||||
|
||||
[http_sample_send_cgi_response]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
[section Defer Body Type]
|
||||
|
||||
Sophisticated servers may wish to defer the choice of the Body template type
|
||||
until after the header is available. Then, a body type may be chosen
|
||||
depending on the header contents. For example, depending on the verb,
|
||||
target path, or target query parameters. To accomplish this, a parser
|
||||
is declared to read in the header only, using a trivial body type such as
|
||||
[link beast.ref.http__empty_body `empty_body`]. Then, a new parser is constructed
|
||||
from this existing parser where the body type is conditionally determined
|
||||
by information from the header or elsewhere.
|
||||
|
||||
This example illustrates how a server may make the commitment of a body
|
||||
type depending on the method verb:
|
||||
|
||||
[http_sample_defer_body]
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[section HTTP Relay]
|
||||
|
||||
An HTTP proxy acts as a relay between client and server. The proxy reads a
|
||||
|
||||
Reference in New Issue
Block a user