diff --git a/CHANGELOG.md b/CHANGELOG.md index 9699ab47..918ff200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ API Changes: * Tidy up chunk decorator * Rename to buffer_cat_view * Consolidate parsers to parser.hpp +* Rename to parser -------------------------------------------------------------------------------- diff --git a/doc/0_main.qbk b/doc/0_main.qbk index f62407cb..d8b727c9 100644 --- a/doc/0_main.qbk +++ b/doc/0_main.qbk @@ -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 diff --git a/doc/3_0_http.qbk b/doc/3_0_http.qbk index 687476a1..cc42f23f 100644 --- a/doc/3_0_http.qbk +++ b/doc/3_0_http.qbk @@ -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__. ] ] ] diff --git a/doc/3_5_parser_streams.qbk b/doc/3_5_parser_streams.qbk index 9966de4a..6ffb74fd 100644 --- a/doc/3_5_parser_streams.qbk +++ b/doc/3_5_parser_streams.qbk @@ -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 + using request_parser = parser; + ``` +]] +[[ + [link beast.ref.http__response_parser `response_parser`] +][ + ``` + /// An HTTP/1 parser for producing a response message. + template + using response_parser = parser; + ``` +]] ] [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 p; + parser p; // Create a serializer from the message contained in the parser. serializer sr{p.get()}; diff --git a/doc/3_7_parser_buffers.qbk b/doc/3_7_parser_buffers.qbk index 7d733b18..9f65e3f4 100644 --- a/doc/3_7_parser_buffers.qbk +++ b/doc/3_7_parser_buffers.qbk @@ -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 parser; + parser parser; do { diff --git a/doc/concept/BodyWriter.qbk b/doc/concept/BodyWriter.qbk index 62b245f4..776bd2c7 100644 --- a/doc/concept/BodyWriter.qbk +++ b/doc/concept/BodyWriter.qbk @@ -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: diff --git a/doc/quickref.xml b/doc/quickref.xml index 99285cb1..a0b9bd4d 100644 --- a/doc/quickref.xml +++ b/doc/quickref.xml @@ -39,7 +39,7 @@ header header_parser message - message_parser + parser no_chunk_decorator request request_parser diff --git a/include/beast/http/impl/parser.ipp b/include/beast/http/impl/parser.ipp index f00b6dbc..67dc4d92 100644 --- a/include/beast/http/impl/parser.ipp +++ b/include/beast/http/impl/parser.ipp @@ -22,8 +22,8 @@ header_parser(Arg0&& arg0, ArgN&&... argn) template template -message_parser:: -message_parser(Arg1&& arg1, ArgN&&... argn) +parser:: +parser(Arg1&& arg1, ArgN&&... argn) : m_(std::forward(arg1), std::forward(argn)...) { @@ -31,8 +31,8 @@ message_parser(Arg1&& arg1, ArgN&&... argn) template template -message_parser:: -message_parser(header_parser< +parser:: +parser(header_parser< isRequest, Fields>&& parser, Args&&... args) : base_type(std::move(static_cast>&>(parser))) diff --git a/include/beast/http/impl/read.ipp b/include/beast/http/impl/read.ipp index 4dcb58d9..39c7c412 100644 --- a/include/beast/http/impl/read.ipp +++ b/include/beast/http/impl/read.ipp @@ -309,7 +309,7 @@ template; + parser; using message_type = message; @@ -739,7 +739,7 @@ read( "Body requirements not met"); static_assert(is_body_writer::value, "BodyWriter requirements not met"); - message_parser p; + parser p; p.eager(true); read(stream, buffer, p.base(), ec); if(ec) diff --git a/include/beast/http/parser.hpp b/include/beast/http/parser.hpp index 31aab2b5..aacc3b07 100644 --- a/include/beast/http/parser.hpp +++ b/include/beast/http/parser.hpp @@ -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 -class message_parser +class parser : public basic_parser> + parser> { static_assert(is_body::value, "Body requirements not met"); @@ -225,7 +225,7 @@ class message_parser "BodyWriter requirements not met"); using base_type = basic_parser>; + parser>; using writer_type = typename Body::writer; @@ -237,20 +237,20 @@ public: using value_type = message; /// 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 @@ -272,10 +272,10 @@ public: std::decay::type, header_parser>::value && ! std::is_same::type, message_parser>::value + std::decay::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 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 -using request_parser = message_parser; +using request_parser = parser; -/// A parser for producing HTTP/1 messages +/// An HTTP/1 parser for producing a response message. template -using response_parser = message_parser; +using response_parser = parser; } // http } // beast diff --git a/test/http/design.cpp b/test/http/design.cpp index f82bf526..24bdb4f9 100644 --- a/test/http/design.cpp +++ b/test/http/design.cpp @@ -407,7 +407,7 @@ public: char buf[2048]; // Create a parser with a buffer body to read from the input. - message_parser p; + parser p; // Create a serializer from the message contained in the parser. serializer sr{p.get()}; @@ -534,7 +534,7 @@ public: error_code& ec) { // Create the message parser - message_parser parser; + parser parser; do { @@ -641,7 +641,7 @@ public: read_some(p.server, buffer, parser); buffer.consume(bytes_used); - message_parser parser2( + request_parser parser2( std::move(parser)); while(! parser2.is_done()) diff --git a/test/http/dynamic_body.cpp b/test/http/dynamic_body.cpp index 7818e327..37e3fb5d 100644 --- a/test/http/dynamic_body.cpp +++ b/test/http/dynamic_body.cpp @@ -35,7 +35,7 @@ public: "\r\n" "xyz"; test::string_istream ss(ios_, s); - message_parser p; + response_parser p; multi_buffer b; read(ss, b, p); auto const& m = p.get(); diff --git a/test/http/parser.cpp b/test/http/parser.cpp index aa9d7ca1..6bbfe384 100644 --- a/test/http/parser.cpp +++ b/test/http/parser.cpp @@ -83,7 +83,7 @@ class parser_test public: template using parser_type = - message_parser; + parser; static boost::asio::const_buffers_1 @@ -319,7 +319,7 @@ public: // skip body { error_code ec; - message_parser p; + response_parser 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 p1{std::move(p0)}; + request_parser p1{std::move(p0)}; read(ss, b, p1, ec); BEAST_EXPECTS(! ec, ec.message()); BEAST_EXPECT(p1.get().body == "*****"); diff --git a/test/http/read.cpp b/test/http/read.cpp index 7428b4d1..2cd82a75 100644 --- a/test/http/read.cpp +++ b/test/http/read.cpp @@ -299,7 +299,7 @@ public: { multi_buffer b; test::string_istream ss(ios_, ""); - message_parser p; + request_parser 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 p; + request_parser p; error_code ec; async_read(ss, b, p, do_yield[ec]); BEAST_EXPECT(ec == http::error::end_of_stream);