mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
Rename to parser (API Change):
* message_parser is renamed to parser
This commit is contained in:
@ -7,6 +7,7 @@ API Changes:
|
||||
* Tidy up chunk decorator
|
||||
* Rename to buffer_cat_view
|
||||
* Consolidate parsers to parser.hpp
|
||||
* Rename to parser
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -63,8 +63,8 @@
|
||||
[def __header__ [link beast.ref.http__header `header`]]
|
||||
[def __header_parser__ [link beast.ref.http__header_parser `header_parser`]]
|
||||
[def __message__ [link beast.ref.http__message `message`]]
|
||||
[def __message_parser__ [link beast.ref.http__message_parser `message_parser`]]
|
||||
[def __multi_buffer__ [link beast.ref.multi_buffer `multi_buffer`]]
|
||||
[def __parser__ [link beast.ref.http__parser `parser`]]
|
||||
[def __serializer__ [link beast.ref.http__serializer `serializer`]]
|
||||
|
||||
Beast is a cross-platform, header-only C++11 library for low-level HTTP
|
||||
|
@ -69,8 +69,8 @@ format using __Asio__. Specifically, the library provides:
|
||||
][
|
||||
[Parsing]
|
||||
[
|
||||
The __message_parser__ attempts to convert a series of
|
||||
octet buffers into a __message__.
|
||||
The __parser__ attempts to convert a series of octet
|
||||
buffers into a __message__.
|
||||
]
|
||||
]
|
||||
]
|
||||
|
@ -26,15 +26,15 @@ defined types deriving from the basic parser are possible:
|
||||
[table Parser Implementations
|
||||
[[Name][Description]]
|
||||
[[
|
||||
__message_parser__
|
||||
__parser__
|
||||
][
|
||||
```
|
||||
/// A parser for a message
|
||||
/// 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 Fields> // The type of container representing the fields
|
||||
class message_parser
|
||||
class parser
|
||||
: public basic_parser<...>;
|
||||
```
|
||||
]]
|
||||
@ -42,7 +42,7 @@ defined types deriving from the basic parser are possible:
|
||||
__header_parser__
|
||||
][
|
||||
```
|
||||
/// A parser for a header
|
||||
/// An HTTP/1 parser for producing a header.
|
||||
template<
|
||||
bool isRequest, // `true` to parse an HTTP request
|
||||
class Fields> // The type of container representing the fields
|
||||
@ -50,6 +50,24 @@ defined types deriving from the basic parser are possible:
|
||||
: public basic_parser<...>;
|
||||
```
|
||||
]]
|
||||
[[
|
||||
[link beast.ref.http__request_parser `request_parser`]
|
||||
][
|
||||
```
|
||||
/// An HTTP/1 parser for producing a request message.
|
||||
template<class Body, class Fields = fields>
|
||||
using request_parser = parser<true, Body, Fields>;
|
||||
```
|
||||
]]
|
||||
[[
|
||||
[link beast.ref.http__response_parser `response_parser`]
|
||||
][
|
||||
```
|
||||
/// An HTTP/1 parser for producing a response message.
|
||||
template<class Body, class Fields = fields>
|
||||
using response_parser = parser<false, Body, Fields>;
|
||||
```
|
||||
]]
|
||||
]
|
||||
|
||||
[note
|
||||
@ -134,8 +152,8 @@ immediate informational response before sending the the message body, which
|
||||
presumably may be expensive to compute or large. This behavior is described in
|
||||
[@https://tools.ietf.org/html/rfc7231#section-5.1.1 rfc7231 section 5.1.1].
|
||||
Handling the Expect field can be implemented easily in a server by constructing
|
||||
a __message_parser__ to read the header first, then send an informational
|
||||
HTTP response, and finally read the body using the same parser instance. A
|
||||
a __parser__ to read the header first, then send an informational HTTP
|
||||
response, and finally read the body using the same parser instance. A
|
||||
synchronous version of this server action looks like this:
|
||||
```
|
||||
/** Receive a request, handling Expect: 100-continue if present.
|
||||
@ -209,7 +227,7 @@ The example that follows implements a synchronous HTTP relay. It uses a
|
||||
fixed size buffer, to avoid reading in the entire body so that the upstream
|
||||
connection sees a header without unnecessary latency. This example brings
|
||||
together all of the concepts discussed so far, it uses both a __serializer__
|
||||
and a __message_parser__ to achieve its goal:
|
||||
and a __parser__ to achieve its goal:
|
||||
```
|
||||
/** Relay an HTTP message.
|
||||
|
||||
@ -265,7 +283,7 @@ relay(
|
||||
char buf[2048];
|
||||
|
||||
// Create a parser with a buffer body to read from the input.
|
||||
message_parser<isRequest, buffer_body, Fields> p;
|
||||
parser<isRequest, buffer_body, Fields> p;
|
||||
|
||||
// Create a serializer from the message contained in the parser.
|
||||
serializer<isRequest, buffer_body, Fields> sr{p.get()};
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
[section:parser_buffers Buffer-Oriented Parsing]
|
||||
|
||||
In extreme cases, users may wish to create an instance of __message_parser__,
|
||||
In extreme cases, users may wish to create an instance of __parser__,
|
||||
__header_parser__, or a user-defined type derived from __basic_parser__ and
|
||||
invoke its methods directly instead of using the provided stream algorithms.
|
||||
This could be useful for implementing algorithms on streams whose interface
|
||||
@ -58,7 +58,7 @@ parse_istream(
|
||||
error_code& ec)
|
||||
{
|
||||
// Create the message parser
|
||||
message_parser<isRequest, Body, Fields> parser;
|
||||
parser<isRequest, Body, Fields> parser;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
A [*BodyWriter] provides an online algorithm to transfer a series of zero
|
||||
or more buffers containing parsed body octets into a message container. The
|
||||
__message_parser__ creates an instance of this type when needed, and calls into
|
||||
__parser__ creates an instance of this type when needed, and calls into
|
||||
it zero or more times to transfer buffers. The interface of [*BodyWriter]
|
||||
is intended to allow the conversion of buffers into these scenarios for
|
||||
representation:
|
||||
|
@ -39,7 +39,7 @@
|
||||
<member><link linkend="beast.ref.http__header">header</link></member>
|
||||
<member><link linkend="beast.ref.http__header_parser">header_parser</link></member>
|
||||
<member><link linkend="beast.ref.http__message">message</link></member>
|
||||
<member><link linkend="beast.ref.http__message_parser">message_parser</link></member>
|
||||
<member><link linkend="beast.ref.http__parser">parser</link></member>
|
||||
<member><link linkend="beast.ref.http__no_chunk_decorator">no_chunk_decorator</link></member>
|
||||
<member><link linkend="beast.ref.http__request">request</link></member>
|
||||
<member><link linkend="beast.ref.http__request_parser">request_parser</link></member>
|
||||
|
@ -22,8 +22,8 @@ header_parser(Arg0&& arg0, ArgN&&... argn)
|
||||
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
template<class Arg1, class... ArgN, class>
|
||||
message_parser<isRequest, Body, Fields>::
|
||||
message_parser(Arg1&& arg1, ArgN&&... argn)
|
||||
parser<isRequest, Body, Fields>::
|
||||
parser(Arg1&& arg1, ArgN&&... argn)
|
||||
: m_(std::forward<Arg1>(arg1),
|
||||
std::forward<ArgN>(argn)...)
|
||||
{
|
||||
@ -31,8 +31,8 @@ message_parser(Arg1&& arg1, ArgN&&... argn)
|
||||
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
template<class... Args>
|
||||
message_parser<isRequest, Body, Fields>::
|
||||
message_parser(header_parser<
|
||||
parser<isRequest, Body, Fields>::
|
||||
parser(header_parser<
|
||||
isRequest, Fields>&& parser, Args&&... args)
|
||||
: base_type(std::move(static_cast<basic_parser<
|
||||
isRequest, header_parser<isRequest, Fields>>&>(parser)))
|
||||
|
@ -309,7 +309,7 @@ template<class Stream, class DynamicBuffer,
|
||||
class read_msg_op
|
||||
{
|
||||
using parser_type =
|
||||
message_parser<isRequest, Body, Fields>;
|
||||
parser<isRequest, Body, Fields>;
|
||||
|
||||
using message_type =
|
||||
message<isRequest, Body, Fields>;
|
||||
@ -739,7 +739,7 @@ read(
|
||||
"Body requirements not met");
|
||||
static_assert(is_body_writer<Body>::value,
|
||||
"BodyWriter requirements not met");
|
||||
message_parser<isRequest, Body, Fields> p;
|
||||
parser<isRequest, Body, Fields> p;
|
||||
p.eager(true);
|
||||
read(stream, buffer, p.base(), ec);
|
||||
if(ec)
|
||||
|
@ -20,7 +20,7 @@
|
||||
namespace beast {
|
||||
namespace http {
|
||||
|
||||
/** A parser for producing HTTP/1 headers.
|
||||
/** An HTTP/1 parser for producing a header.
|
||||
|
||||
This class uses the basic HTTP/1 wire format parser to convert
|
||||
a series of octets into a @ref header.
|
||||
@ -199,7 +199,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
/** A parser for producing HTTP/1 messages.
|
||||
/** An HTTP/1 parser for producing a message.
|
||||
|
||||
This class uses the basic HTTP/1 wire format parser to convert
|
||||
a series of octets into a @ref message.
|
||||
@ -214,9 +214,9 @@ private:
|
||||
@note A new instance of the parser is required for each message.
|
||||
*/
|
||||
template<bool isRequest, class Body, class Fields = fields>
|
||||
class message_parser
|
||||
class parser
|
||||
: public basic_parser<isRequest,
|
||||
message_parser<isRequest, Body, Fields>>
|
||||
parser<isRequest, Body, Fields>>
|
||||
{
|
||||
static_assert(is_body<Body>::value,
|
||||
"Body requirements not met");
|
||||
@ -225,7 +225,7 @@ class message_parser
|
||||
"BodyWriter requirements not met");
|
||||
|
||||
using base_type = basic_parser<isRequest,
|
||||
message_parser<isRequest, Body, Fields>>;
|
||||
parser<isRequest, Body, Fields>>;
|
||||
|
||||
using writer_type = typename Body::writer;
|
||||
|
||||
@ -237,20 +237,20 @@ public:
|
||||
using value_type = message<isRequest, Body, Fields>;
|
||||
|
||||
/// Constructor (default)
|
||||
message_parser() = default;
|
||||
parser() = default;
|
||||
|
||||
/// Copy constructor (disallowed)
|
||||
message_parser(message_parser const&) = delete;
|
||||
parser(parser const&) = delete;
|
||||
|
||||
/// Copy assignment (disallowed)
|
||||
message_parser& operator=(message_parser const&) = delete;
|
||||
parser& operator=(parser const&) = delete;
|
||||
|
||||
/** Move constructor.
|
||||
|
||||
After the move, the only valid operation
|
||||
on the moved-from object is destruction.
|
||||
*/
|
||||
message_parser(message_parser&& other);
|
||||
parser(parser&& other);
|
||||
|
||||
/** Constructor
|
||||
|
||||
@ -259,7 +259,7 @@ public:
|
||||
|
||||
@note This function participates in overload
|
||||
resolution only if the first argument is not a
|
||||
@ref http::header_parser or @ref message_parser.
|
||||
@ref http::header_parser or @ref parser.
|
||||
*/
|
||||
#if BEAST_DOXYGEN
|
||||
template<class... Args>
|
||||
@ -272,10 +272,10 @@ public:
|
||||
std::decay<Arg1>::type,
|
||||
header_parser<isRequest, Fields>>::value &&
|
||||
! std::is_same<typename
|
||||
std::decay<Arg1>::type, message_parser>::value
|
||||
std::decay<Arg1>::type, parser>::value
|
||||
>::type>
|
||||
explicit
|
||||
message_parser(Arg1&& arg1, ArgN&&... argn);
|
||||
parser(Arg1&& arg1, ArgN&&... argn);
|
||||
#endif
|
||||
|
||||
/** Construct a message parser from a @ref header_parser.
|
||||
@ -285,7 +285,7 @@ public:
|
||||
*/
|
||||
template<class... Args>
|
||||
explicit
|
||||
message_parser(header_parser<
|
||||
parser(header_parser<
|
||||
isRequest, Fields>&& parser, Args&&... args);
|
||||
|
||||
/** Returns the parsed message.
|
||||
@ -330,7 +330,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class basic_parser<
|
||||
isRequest, message_parser>;
|
||||
isRequest, parser>;
|
||||
|
||||
void
|
||||
on_request(
|
||||
@ -398,13 +398,13 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
/// A parser for producing HTTP/1 messages
|
||||
/// An HTTP/1 parser for producing a request message.
|
||||
template<class Body, class Fields = fields>
|
||||
using request_parser = message_parser<true, Body, Fields>;
|
||||
using request_parser = parser<true, Body, Fields>;
|
||||
|
||||
/// A parser for producing HTTP/1 messages
|
||||
/// An HTTP/1 parser for producing a response message.
|
||||
template<class Body, class Fields = fields>
|
||||
using response_parser = message_parser<false, Body, Fields>;
|
||||
using response_parser = parser<false, Body, Fields>;
|
||||
|
||||
} // http
|
||||
} // beast
|
||||
|
@ -407,7 +407,7 @@ public:
|
||||
char buf[2048];
|
||||
|
||||
// Create a parser with a buffer body to read from the input.
|
||||
message_parser<isRequest, buffer_body, Fields> p;
|
||||
parser<isRequest, buffer_body, Fields> p;
|
||||
|
||||
// Create a serializer from the message contained in the parser.
|
||||
serializer<isRequest, buffer_body, Fields> sr{p.get()};
|
||||
@ -534,7 +534,7 @@ public:
|
||||
error_code& ec)
|
||||
{
|
||||
// Create the message parser
|
||||
message_parser<isRequest, Body, Fields> parser;
|
||||
parser<isRequest, Body, Fields> parser;
|
||||
|
||||
do
|
||||
{
|
||||
@ -641,7 +641,7 @@ public:
|
||||
read_some(p.server, buffer, parser);
|
||||
buffer.consume(bytes_used);
|
||||
|
||||
message_parser<true, string_body, fields> parser2(
|
||||
request_parser<string_body> parser2(
|
||||
std::move(parser));
|
||||
|
||||
while(! parser2.is_done())
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
"\r\n"
|
||||
"xyz";
|
||||
test::string_istream ss(ios_, s);
|
||||
message_parser<false, dynamic_body, fields> p;
|
||||
response_parser<dynamic_body> p;
|
||||
multi_buffer b;
|
||||
read(ss, b, p);
|
||||
auto const& m = p.get();
|
||||
|
@ -83,7 +83,7 @@ class parser_test
|
||||
public:
|
||||
template<bool isRequest>
|
||||
using parser_type =
|
||||
message_parser<isRequest, string_body, fields>;
|
||||
parser<isRequest, string_body, fields>;
|
||||
|
||||
static
|
||||
boost::asio::const_buffers_1
|
||||
@ -319,7 +319,7 @@ public:
|
||||
// skip body
|
||||
{
|
||||
error_code ec;
|
||||
message_parser<false, string_body, fields> p;
|
||||
response_parser<string_body> p;
|
||||
p.skip(true);
|
||||
p.put(buf(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
@ -353,8 +353,7 @@ public:
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(p0.is_header_done());
|
||||
BEAST_EXPECT(! p0.is_done());
|
||||
message_parser<true,
|
||||
string_body, fields> p1{std::move(p0)};
|
||||
request_parser<string_body> p1{std::move(p0)};
|
||||
read(ss, b, p1, ec);
|
||||
BEAST_EXPECTS(! ec, ec.message());
|
||||
BEAST_EXPECT(p1.get().body == "*****");
|
||||
|
@ -299,7 +299,7 @@ public:
|
||||
{
|
||||
multi_buffer b;
|
||||
test::string_istream ss(ios_, "");
|
||||
message_parser<true, dynamic_body, fields> p;
|
||||
request_parser<dynamic_body> p;
|
||||
error_code ec;
|
||||
read(ss, b, p, ec);
|
||||
BEAST_EXPECT(ec == http::error::end_of_stream);
|
||||
@ -307,7 +307,7 @@ public:
|
||||
{
|
||||
multi_buffer b;
|
||||
test::string_istream ss(ios_, "");
|
||||
message_parser<true, dynamic_body, fields> p;
|
||||
request_parser<dynamic_body> p;
|
||||
error_code ec;
|
||||
async_read(ss, b, p, do_yield[ec]);
|
||||
BEAST_EXPECT(ec == http::error::end_of_stream);
|
||||
|
Reference in New Issue
Block a user