mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
Add skip_body parser option
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
* Fixes and documentation for teardown and use with SSL:
|
||||
* Add example code to rfc7230 javadocs
|
||||
* Remove extraneous header file <beast/http/status.hpp>
|
||||
* Add skip_body parser option
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
<simplelist type="vert" columns="1">
|
||||
<member><link linkend="beast.ref.http__body_max_size">body_max_size</link></member>
|
||||
<member><link linkend="beast.ref.http__headers_max_size">headers_max_size</link></member>
|
||||
<member><link linkend="beast.ref.http__skip_body">skip_body</link></member>
|
||||
</simplelist>
|
||||
<bridgehead renderas="sect3">Type Traits</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
|
@ -35,6 +35,37 @@ struct parser_response
|
||||
|
||||
} // detail
|
||||
|
||||
/** Skip body option.
|
||||
|
||||
The options controls whether or not the parser expects to see a
|
||||
HTTP body, regardless of the presence or absence of certain fields
|
||||
such as Content-Length.
|
||||
|
||||
Depending on the request, some responses do not carry a body.
|
||||
For example, a 200 response to a CONNECT request from a tunneling
|
||||
proxy. In these cases, callers use the @ref skip_body option to
|
||||
inform the parser that no body is expected. The parser will consider
|
||||
the message complete after the all headers have been received.
|
||||
|
||||
Example:
|
||||
@code
|
||||
parser_v1<true, empty_body, headers> p;
|
||||
p.set_option(skip_body{true});
|
||||
@endcode
|
||||
|
||||
@note Objects of this type are passed to @ref basic_parser_v1::set_option.
|
||||
*/
|
||||
struct skip_body
|
||||
{
|
||||
bool value;
|
||||
|
||||
explicit
|
||||
skip_body(bool v)
|
||||
: value(v)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/** A parser for producing HTTP/1 messages.
|
||||
|
||||
This class uses the basic HTTP/1 wire format parser to convert
|
||||
@ -62,6 +93,7 @@ private:
|
||||
std::string value_;
|
||||
message_type m_;
|
||||
typename message_type::body_type::reader r_;
|
||||
std::uint8_t skip_body_ = 0;
|
||||
|
||||
public:
|
||||
parser_v1(parser_v1&&) = default;
|
||||
@ -81,6 +113,13 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
/// Set the expect body option.
|
||||
void
|
||||
set_option(skip_body const& o)
|
||||
{
|
||||
skip_body_ = o.value ? 1 : 0;
|
||||
}
|
||||
|
||||
/** Returns the parsed message.
|
||||
|
||||
Only valid if `complete()` would return `true`.
|
||||
@ -176,7 +215,7 @@ private:
|
||||
{
|
||||
flush();
|
||||
m_.version = 10 * this->http_major() + this->http_minor();
|
||||
return 0;
|
||||
return skip_body_;
|
||||
}
|
||||
|
||||
void on_request(error_code& ec)
|
||||
|
@ -61,6 +61,19 @@ public:
|
||||
expect(m.headers["Server"] == "test");
|
||||
expect(m.body == "*");
|
||||
}
|
||||
// skip body
|
||||
{
|
||||
error_code ec;
|
||||
parser_v1<false, string_body, headers> p;
|
||||
std::string const s =
|
||||
"HTTP/1.1 200 Connection Established\r\n"
|
||||
"Proxy-Agent: Zscaler/5.1\r\n"
|
||||
"\r\n";
|
||||
p.set_option(skip_body{true});
|
||||
p.write(buffer(s), ec);
|
||||
expect(! ec);
|
||||
expect(p.complete());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user