diff --git a/CHANGELOG.md b/CHANGELOG.md index 79e46a74..520cc3a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,16 @@ Version 62: * Clear the error faster * Avoid explicit operator bool for error +API Changes: + +* parser requires basic_fields + +Actions Required: + +* Callers using `parser` with Fields types other than basic_fields + will need to create their own subclass of basic_parser to work + with their custom fields type. + -------------------------------------------------------------------------------- Version 61: diff --git a/example/doc/http_examples.hpp b/example/doc/http_examples.hpp index 977aade6..af3335b3 100644 --- a/example/doc/http_examples.hpp +++ b/example/doc/http_examples.hpp @@ -464,7 +464,6 @@ do_head_request( */ template< bool isRequest, - class Fields = fields, class SyncWriteStream, class SyncReadStream, class DynamicBuffer, @@ -487,10 +486,10 @@ relay( char buf[2048]; // Create a parser with a buffer body to read from the input. - parser p; + parser p; // Create a serializer from the message contained in the parser. - serializer sr{p.get()}; + serializer sr{p.get()}; // Read just the header from the input read_header(input, buffer, p, ec); @@ -684,13 +683,12 @@ write_ostream( template< class Allocator, bool isRequest, - class Body, - class Fields> + class Body> void read_istream( std::istream& is, basic_flat_buffer& buffer, - message& msg, + message& msg, error_code& ec) { // Create the message parser @@ -700,7 +698,7 @@ read_istream( // a move construction in case the caller has constructed // their message in a non-default way. // - parser p{std::move(msg)}; + parser p{std::move(msg)}; do { diff --git a/include/beast/http/impl/parser.ipp b/include/beast/http/impl/parser.ipp index 97d3a0f7..9f5ab5a2 100644 --- a/include/beast/http/impl/parser.ipp +++ b/include/beast/http/impl/parser.ipp @@ -14,19 +14,19 @@ namespace beast { namespace http { -template +template template -parser:: +parser:: parser(Arg1&& arg1, ArgN&&... argn) : m_(std::forward(arg1), std::forward(argn)...) { } -template +template template -parser:: -parser(parser&& p, +parser:: +parser(parser&& p, Args&&... args) : base_type(std::move(p)) , m_(p.release(), std::forward(args)...) diff --git a/include/beast/http/impl/read.ipp b/include/beast/http/impl/read.ipp index 04885a25..b530a1c3 100644 --- a/include/beast/http/impl/read.ipp +++ b/include/beast/http/impl/read.ipp @@ -300,15 +300,15 @@ upcall: //------------------------------------------------------------------------------ template class read_msg_op { using parser_type = - parser; + parser; using message_type = - message; + typename parser_type::value_type; struct data { @@ -383,11 +383,11 @@ public: }; template void read_msg_op:: + isRequest, Body, Allocator, Handler>:: operator()(error_code ec) { auto& d = *d_; @@ -693,12 +693,12 @@ async_read( template< class SyncReadStream, class DynamicBuffer, - bool isRequest, class Body, class Fields> + bool isRequest, class Body, class Allocator> void read( SyncReadStream& stream, DynamicBuffer& buffer, - message& msg) + message>& msg) { static_assert(is_sync_read_stream::value, "SyncReadStream requirements not met"); @@ -717,12 +717,12 @@ read( template< class SyncReadStream, class DynamicBuffer, - bool isRequest, class Body, class Fields> + bool isRequest, class Body, class Allocator> void read( SyncReadStream& stream, DynamicBuffer& buffer, - message& msg, + message>& msg, error_code& ec) { static_assert(is_sync_read_stream::value, @@ -733,7 +733,7 @@ read( "Body requirements not met"); static_assert(is_body_writer::value, "BodyWriter requirements not met"); - parser p{std::move(msg)}; + parser p{std::move(msg)}; p.eager(true); read(stream, buffer, p.base(), ec); if(ec) @@ -744,13 +744,13 @@ read( template< class AsyncReadStream, class DynamicBuffer, - bool isRequest, class Body, class Fields, + bool isRequest, class Body, class Allocator, class ReadHandler> async_return_type async_read( AsyncReadStream& stream, DynamicBuffer& buffer, - message& msg, + message>& msg, ReadHandler&& handler) { static_assert(is_async_read_stream::value, @@ -764,7 +764,7 @@ async_read( async_completion init{handler}; detail::read_msg_op>{ init.completion_handler, stream, buffer, msg}( error_code{}); diff --git a/include/beast/http/parser.hpp b/include/beast/http/parser.hpp index c6c4ec46..f6182990 100644 --- a/include/beast/http/parser.hpp +++ b/include/beast/http/parser.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -23,24 +24,27 @@ namespace http { /** 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. + a series of octets into a @ref message using the @ref basic_fields + container to represent the fields. @tparam isRequest Indicates whether a request or response will be parsed. - @tparam Body The type used to represent the body. + @tparam Body The type used to represent the body. This must + meet the requirements of @b Body. - @tparam Fields The type of container used to represent the fields. + @tparam Allocator The type of allocator used with the + @ref basic_fields container. @note A new instance of the parser is required for each message. */ template< bool isRequest, class Body, - class Fields = fields> + class Allocator = std::allocator> class parser : public basic_parser> + parser> { static_assert(is_body::value, "Body requirements not met"); @@ -52,14 +56,15 @@ class parser friend class parser; using base_type = basic_parser>; + parser>; - message m_; + message> m_; boost::optional wr_; public: /// The type of message returned by the parser - using value_type = message; + using value_type = + message>; /// Constructor (default) parser() = default; @@ -126,6 +131,9 @@ public: @throws std::invalid_argument Thrown when the constructed-from parser has already initialized a body writer. + + @note This function participates in overload resolution only + if the other parser uses a different body type. */ #if BEAST_DOXYGEN template @@ -135,13 +143,13 @@ public: ! std::is_same::value>::type> #endif explicit - parser(parser&& parser, - Args&&... args); + parser(parser&& parser, Args&&... args); /** Returns the parsed message. - Depending on the progress of the parser, portions - of this object may be incomplete. + Depending on the parser's progress, + parts of this object may be incomplete. */ value_type const& get() const @@ -151,8 +159,8 @@ public: /** Returns the parsed message. - Depending on the progress of the parser, portions - of this object may be incomplete. + Depending on the parser's progress, + parts of this object may be incomplete. */ value_type& get() @@ -163,8 +171,8 @@ public: /** Returns ownership of the parsed message. Ownership is transferred to the caller. - Depending on the progress of the parser, portions - of this object may be incomplete. + Depending on the parser's progress, + parts of this object may be incomplete. @par Requires @@ -253,12 +261,12 @@ private: }; /// An HTTP/1 parser for producing a request message. -template -using request_parser = parser; +template> +using request_parser = parser; /// An HTTP/1 parser for producing a response message. -template -using response_parser = parser; +template> +using response_parser = parser; } // http } // beast diff --git a/include/beast/http/read.hpp b/include/beast/http/read.hpp index 95c479d6..72fea92f 100644 --- a/include/beast/http/read.hpp +++ b/include/beast/http/read.hpp @@ -614,12 +614,12 @@ async_read( template< class SyncReadStream, class DynamicBuffer, - bool isRequest, class Body, class Fields> + bool isRequest, class Body, class Allocator> void read( SyncReadStream& stream, DynamicBuffer& buffer, - message& msg); + message>& msg); /** Read a complete message from a stream. @@ -666,12 +666,12 @@ read( template< class SyncReadStream, class DynamicBuffer, - bool isRequest, class Body, class Fields> + bool isRequest, class Body, class Allocator> void read( SyncReadStream& stream, DynamicBuffer& buffer, - message& msg, + message>& msg, error_code& ec); /** Read a complete message from a stream asynchronously. @@ -735,7 +735,7 @@ read( template< class AsyncReadStream, class DynamicBuffer, - bool isRequest, class Body, class Fields, + bool isRequest, class Body, class Allocator, class ReadHandler> #if BEAST_DOXYGEN void_or_deduced @@ -746,7 +746,7 @@ async_return_type< async_read( AsyncReadStream& stream, DynamicBuffer& buffer, - message& msg, + message>& msg, ReadHandler&& handler); } // http diff --git a/test/http/parser.cpp b/test/http/parser.cpp index a8436718..f63e2834 100644 --- a/test/http/parser.cpp +++ b/test/http/parser.cpp @@ -32,7 +32,7 @@ class parser_test public: template using parser_type = - parser; + parser; static boost::asio::const_buffers_1