From 895c9fa7ed79df27dca119d0395941045289e2a3 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 30 Oct 2017 17:08:52 -0700 Subject: [PATCH] BodyReader and BodyWriter names are swapped (API Change): Body::reader and Body::writer meanings are reversed, for consistency with the names of the stream operations: * Body::reader is used for read, read_some, async_read, async_read_some * Body::writer is used for write, write_some, async_write, async_write_some Actions Required: * Swap the reader and writer names for user defined Body types * Swap use of is_body_reader and is_body_writer --- CHANGELOG.md | 3 + doc/qbk/04_http/09_custom_body.qbk | 38 +++--- doc/qbk/07_concepts/Body.qbk | 26 ++-- doc/qbk/07_concepts/BodyReader.qbk | 103 +++++++-------- doc/qbk/07_concepts/BodyWriter.qbk | 103 ++++++++------- doc/qbk/quickref.xml | 2 +- .../boost/beast/http/basic_dynamic_body.hpp | 80 ++++++------ include/boost/beast/http/basic_file_body.hpp | 44 +++---- include/boost/beast/http/buffer_body.hpp | 120 +++++++++--------- include/boost/beast/http/empty_body.hpp | 72 +++++------ .../boost/beast/http/impl/file_body_win32.ipp | 12 +- include/boost/beast/http/impl/parser.ipp | 2 +- include/boost/beast/http/impl/read.ipp | 12 +- include/boost/beast/http/impl/write.ipp | 44 +++---- include/boost/beast/http/parser.hpp | 18 +-- include/boost/beast/http/serializer.hpp | 38 +++--- include/boost/beast/http/span_body.hpp | 88 ++++++------- include/boost/beast/http/string_body.hpp | 82 ++++++------ include/boost/beast/http/type_traits.hpp | 108 ++++++++-------- include/boost/beast/http/vector_body.hpp | 82 ++++++------ test/beast/http/empty_body.cpp | 2 +- test/beast/http/serializer.cpp | 8 +- test/beast/http/span_body.cpp | 4 +- test/beast/http/string_body.cpp | 2 +- test/beast/http/type_traits.cpp | 6 +- test/beast/http/vector_body.cpp | 2 +- test/beast/http/write.cpp | 16 +-- test/doc/exemplars.cpp | 42 +++--- test/doc/http_snippets.cpp | 6 +- 29 files changed, 582 insertions(+), 583 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3659c118..c9a848a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,13 @@ Version 132: API Changes: * Fields::writer replaces Fields::reader +* BodyReader and BodyWriter names are swapped Actions Required: * Rename reader to writer for user defined Fields +* Swap the reader and writer names for user defined Body types +* Swap use of is_body_reader and is_body_writer -------------------------------------------------------------------------------- diff --git a/doc/qbk/04_http/09_custom_body.qbk b/doc/qbk/04_http/09_custom_body.qbk index 3fa9f5f1..495416df 100644 --- a/doc/qbk/04_http/09_custom_body.qbk +++ b/doc/qbk/04_http/09_custom_body.qbk @@ -17,10 +17,10 @@ shows the customization points available to user-defined body types: /// Defines a Body type struct body { - /// This determines the type of the `message::body` member + /// This determines the return type of the `message::body` member function using value_type = ...; - /// An optional function, returns the body's payload size + /// An optional function, returns the body's payload size (which may be zero) static std::uint64_t size(value_type const& v); @@ -48,17 +48,17 @@ The meaning of the nested types is as follows [`reader`] [ An optional nested type meeting the requirements of __BodyReader__, - which provides the algorithm for converting the body representation - to a forward range of buffer sequences. - If present this body type may be used with a __serializer__. + which provides the algorithm for storing a forward range of buffer + sequences in the body representation. + If present, this body type may be used with a __parser__. ] ][ [`writer`] [ An optional nested type meeting the requirements of __BodyWriter__, - which provides the algorithm for storing a forward range of buffer - sequences in the body representation. - If present, this body type may be used with a __parser__. + which provides the algorithm for converting the body representation + to a forward range of buffer sequences. + If present this body type may be used with a __serializer__. ] ] ] @@ -67,7 +67,7 @@ The meaning of the nested types is as follows The `value_type` nested type allows the body to define the declaration of the body type as it appears in the message. This can be any type. For -example, a body's value type may specify `std::vector` or even +example, a body's value type may specify `std::vector` or `std::list`. A custom body may even set the value type to something that is not a container for body octets, such as a [@boost:/libs/filesystem/doc/reference.html#class-path `boost::filesystem::path`]. @@ -82,20 +82,14 @@ struct Body { using value_type = boost::property_tree::ptree; - class reader; - + class reader class writer; - - // Optional member - static - std::uint64_t - size(value_type const&); }; ``` As long as a suitable reader or writer is available to provide the algorithm for transferring buffers in and out of the value type, -those bodies may be serialized or parsed. +those bodies may be parsed or serialized. @@ -105,7 +99,9 @@ Use of the flexible __Body__ concept customization point enables authors to preserve the self-contained nature of the __message__ object while allowing domain specific behaviors. Common operations for HTTP servers include sending responses which deliver file contents, and allowing for file uploads. In this -example we build the `basic_file_body` type which supports both reading and +example we build the +[link beast.ref.boost__beast__http__basic_file_body `basic_file_body`] +type which supports both reading and writing to a file on the file system. The interface is a class templated on the type of file used to access the file system, which must meet the requirements of __File__. @@ -124,7 +120,7 @@ file is removed from the file system in between calls. [example_http_file_body_2] -Our implementation of __BodyReader__ will contain a small buffer +Our implementation of __BodyWriter__ will contain a small buffer from which the file contents are read. The buffer is provided to the implementation on each call until everything has been read in. @@ -135,13 +131,13 @@ And here are the definitions for the functions we have declared: [example_http_file_body_4] Files can be read now, and the next step is to allow writing to files -by implementing the __BodyWriter__. The style is similar to the reader, +by implementing the __BodyReader__. The style is similar to the writer, except that buffers are incoming instead of outgoing. Here's the declaration: [example_http_file_body_5] -Finally, here is the implementation of the writer member functions: +Finally, here is the implementation of the reader member functions: [example_http_file_body_6] diff --git a/doc/qbk/07_concepts/Body.qbk b/doc/qbk/07_concepts/Body.qbk index 927425fd..b3eb06c8 100644 --- a/doc/qbk/07_concepts/Body.qbk +++ b/doc/qbk/07_concepts/Body.qbk @@ -33,26 +33,25 @@ In this table: [`B::value_type`] [] [ - The type of the `message::body` member. + The return type of the `message::body` member function. If this is not movable or not copyable, the containing message will be not movable or not copyable. ] -][ - [`B::writer`] - [] - [ - If present, indicates that the body can hold a message body - parsing result. The type must meet the requirements of - __BodyWriter__. The implementation constructs an object of - this type to obtain buffers into which parsed body octets - are placed. - ] ][ [`B::reader`] [] [ - If present, indicates that the body is serializable. The type + If present, indicates that the body can be parsed. The type must meet the requirements of __BodyReader__. The implementation + constructs an object of this type to obtain buffers into which + parsed body octets are placed. + ] +][ + [`B::writer`] + [] + [ + If present, indicates that the body is serializable. The type + must meet the requirements of __BodyWriter__. The implementation constructs an object of this type to obtain buffers representing the message body for serialization. ] @@ -67,7 +66,8 @@ In this table: [ This static member function is optional. It returns the payload size of `body` in bytes not including any chunked transfer encoding. - The function shall not exit via an exception. + The return value may be zero, to indicate that the message is known + to have no payload. The function shall not exit via an exception. When this function is present: diff --git a/doc/qbk/07_concepts/BodyReader.qbk b/doc/qbk/07_concepts/BodyReader.qbk index d63fc2c5..b124307c 100644 --- a/doc/qbk/07_concepts/BodyReader.qbk +++ b/doc/qbk/07_concepts/BodyReader.qbk @@ -9,20 +9,18 @@ [section:BodyReader BodyReader] -A [*BodyReader] provides an -[@https://en.wikipedia.org/wiki/Online_algorithm online algorithm] -to obtain a sequence of zero -or more buffers from a body during serialization. The implementation creates -an instance of this type when needed, and calls into it one or more times to -retrieve buffers holding body octets. The interface of [*BodyReader] is -intended to obtain buffers for these scenarios: +A [*BodyReader] provides an online algorithm to transfer a series of zero +or more buffers containing parsed body octets into a message container. The +__parser__ creates an instance of this type when needed, and calls into +it zero or more times to transfer buffers. The interface of [*BodyReader] +is intended to allow the conversion of buffers into these scenarios for +representation: -* A body that does not entirely fit in memory. -* A body produced incrementally from coroutine output. -* A body represented by zero or more buffers already in memory. -* A body whose size is not known ahead of time. -* Body data generated dynamically from other threads. -* Body data computed algorithmically. +* Storing a body in a dynamic buffer +* Storing a body in a user defined container with a custom allocator +* Transformation of incoming body data before storage, for example + to compress it first. +* Saving body data to a file [heading Associated Types] @@ -37,68 +35,71 @@ In this table: * `B` denotes a __Body__ where `std::is_same::value == true`. * `a` denotes a value of type `R`. -* `m` denotes a possibly const value of type `message&` where - `std::is_same:value == true`. +* `b` is an object whose type meets the requirements of __ConstBufferSequence__ +* `m` denotes a value of type `message&` where + `std::is_same::value == true`. +* `n` is a value of type `boost::optional`. * `ec` is a value of type [link beast.ref.boost__beast__error_code `error_code&`]. -* `R` is the type `boost::optional>`. [table Valid expressions [[Expression] [Type] [Semantics, Pre/Post-conditions]] [ - [`R::const_buffers_type`] - [] - [ - A type which meets the requirements of __ConstBufferSequence__. - This is the type of buffer returned by `R::get`. - ] -][ [`R(m);`] [] [ - Constructible from `m`. The lifetime of `m` is guaranteed - to end no earlier than after the `R` is destroyed. - The reader shall not access the contents of `m` before the - first call to `init`, permitting lazy construction of the + Constructible from `m`. The lifetime of `m` is guaranteed to + end no earlier than after the `R` is destroyed. The constructor + will be called after a complete header is stored in `m`, and + before parsing body octets for messages indicating that a body + is present The reader shall not access the contents of `m` before + the first call to `init`, permitting lazy construction of the message. - The constructor may optionally require that `m` is const, which - has these consequences: - - * If `R` requires that `m` is a const reference, then serializers - constructed for messages with this body type will also require a - const reference to a message, otherwise: - - * If `R` requires that `m` is a non-const reference, then serializers - constructed for messages with this body type will aso require - a non-const reference to a message. + The function will ensure that `!ec` is `true` if there was + no error or set to the appropriate error code if there was one. ] ][ - [`a.init(ec)`] + [`a.init(n, ec)`] [] [ Called once to fully initialize the object before any calls to - `get`. The message body becomes valid before entering this function, + `put`. The message body is valid before entering this function, and remains valid until the reader is destroyed. + The value of `n` will be set to the content length of the + body if known, otherwise `n` will be equal to `boost::none`. + Implementations of [*BodyReader] may use this information to + optimize allocation. + The function will ensure that `!ec` is `true` if there was no error or set to the appropriate error code if there was one. ] ][ - [`a.get(ec)`] - [`R`] + [`a.put(b,ec)`] + [`std::size_t`] [ - Called one or more times after `init` succeeds. This function - returns `boost::none` if all buffers representing the body have - been returned in previous calls or if it sets `ec` to indicate an - error. Otherwise, if there are buffers remaining the function - should return a pair with the first element containing a non-zero - length buffer sequence representing the next set of octets in - the body, while the second element is a `bool` meaning `true` - if there may be additional buffers returned on a subsequent call, - or `false` if the buffer returned on this call is the last - buffer representing the body. + This function is called to append some or all of the buffers + specified by `b` into the body representation. The number of + bytes inserted from `b` is returned. If the number of bytes + inserted is less than the total input, the remainder of the + input will be presented in the next call to `put`. The function will ensure that `!ec` is `true` if there was no error or set to the appropriate error code if there was one. ] +][ + [`a.finish(ec)`] + [] + [ + This function is called when no more body octets are remaining. + The function will ensure that `!ec` is `true` if there was + no error or set to the appropriate error code if there was one. + ] +][ + [`is_body_reader`] + [`std::true_type`] + [ + An alias for `std::true_type` for `B`, otherwise an alias + for `std::false_type`. + ] ]] [heading Exemplar] diff --git a/doc/qbk/07_concepts/BodyWriter.qbk b/doc/qbk/07_concepts/BodyWriter.qbk index 60cb4646..1bacf9c9 100644 --- a/doc/qbk/07_concepts/BodyWriter.qbk +++ b/doc/qbk/07_concepts/BodyWriter.qbk @@ -9,18 +9,20 @@ [section:BodyWriter BodyWriter] -A [*BodyWriter] provides an online algorithm to transfer a series of zero -or more buffers containing parsed body octets into a message container. The -__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: +A [*BodyWriter] provides an +[@https://en.wikipedia.org/wiki/Online_algorithm online algorithm] +to obtain a sequence of zero +or more buffers from a body during serialization. The implementation creates +an instance of this type when needed, and calls into it one or more times to +retrieve buffers holding body octets. The interface of [*BodyWriter] is +intended to obtain buffers for these scenarios: -* Storing a body in a dynamic buffer -* Storing a body in a user defined container with a custom allocator -* Transformation of incoming body data before storage, for example - to compress it first. -* Saving body data to a file +* A body that does not entirely fit in memory. +* A body produced incrementally from coroutine output. +* A body represented by zero or more buffers already in memory. +* A body whose size is not known ahead of time. +* Body data generated dynamically from other threads. +* Body data computed algorithmically. [heading Associated Types] @@ -35,71 +37,68 @@ In this table: * `B` denotes a __Body__ where `std::is_same::value == true`. * `a` denotes a value of type `W`. -* `b` is an object whose type meets the requirements of __ConstBufferSequence__ -* `m` denotes a value of type `message&` where - `std::is_same::value == true`. -* `n` is a value of type `boost::optional`. +* `m` denotes a possibly const value of type `message&` where + `std::is_same:value == true`. * `ec` is a value of type [link beast.ref.boost__beast__error_code `error_code&`]. +* `W` is the type `boost::optional>`. [table Valid expressions [[Expression] [Type] [Semantics, Pre/Post-conditions]] [ + [`W::const_buffers_type`] + [] + [ + A type which meets the requirements of __ConstBufferSequence__. + This is the type of buffer returned by `W::get`. + ] +][ [`W(m);`] [] [ - Constructible from `m`. The lifetime of `m` is guaranteed to - end no earlier than after the `W` is destroyed. The constructor - will be called after a complete header is stored in `m`, and - before parsing body octets for messages indicating that a body - is present The writer shall not access the contents of `m` before - the first call to `init`, permitting lazy construction of the + Constructible from `m`. The lifetime of `m` is guaranteed + to end no earlier than after the `W` is destroyed. + The writer shall not access the contents of `m` before the + first call to `init`, permitting lazy construction of the message. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if there was one. + The constructor may optionally require that `m` is const, which + has these consequences: + + * If `W` requires that `m` is a const reference, then serializers + constructed for messages with this body type will also require a + const reference to a message, otherwise: + + * If `W` requires that `m` is a non-const reference, then serializers + constructed for messages with this body type will aso require + a non-const reference to a message. ] ][ - [`a.init(n, ec)`] + [`a.init(ec)`] [] [ Called once to fully initialize the object before any calls to - `put`. The message body is valid before entering this function, + `get`. The message body becomes valid before entering this function, and remains valid until the writer is destroyed. - The value of `n` will be set to the content length of the - body if known, otherwise `n` will be equal to `boost::none`. - Implementations of [*BodyWriter] may use this information to - optimize allocation. - The function will ensure that `!ec` is `true` if there was no error or set to the appropriate error code if there was one. ] ][ - [`a.put(b,ec)`] - [`std::size_t`] + [`a.get(ec)`] + [`W`] [ - This function is called to append some or all of the buffers - specified by `b` into the body representation. The number of - bytes inserted from `b` is returned. If the number of bytes - inserted is less than the total input, the remainder of the - input will be presented in the next call to `put`. + Called one or more times after `init` succeeds. This function + returns `boost::none` if all buffers representing the body have + been returned in previous calls or if it sets `ec` to indicate an + error. Otherwise, if there are buffers remaining the function + should return a pair with the first element containing a non-zero + length buffer sequence representing the next set of octets in + the body, while the second element is a `bool` meaning `true` + if there may be additional buffers returned on a subsequent call, + or `false` if the buffer returned on this call is the last + buffer representing the body. The function will ensure that `!ec` is `true` if there was no error or set to the appropriate error code if there was one. ] -][ - [`a.finish(ec)`] - [] - [ - This function is called when no more body octets are remaining. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if there was one. - ] -][ - [`is_body_writer`] - [`std::true_type`] - [ - An alias for `std::true_type` for `B`, otherwise an alias - for `std::false_type`. - ] ]] [heading Exemplar] diff --git a/doc/qbk/quickref.xml b/doc/qbk/quickref.xml index 890397df..e282fc23 100644 --- a/doc/qbk/quickref.xml +++ b/doc/qbk/quickref.xml @@ -111,8 +111,8 @@ Type Traits is_body - is_body_writer is_body_reader + is_body_writer is_fields Concepts diff --git a/include/boost/beast/http/basic_dynamic_body.hpp b/include/boost/beast/http/basic_dynamic_body.hpp index 6bc8fa91..76c499c5 100644 --- a/include/boost/beast/http/basic_dynamic_body.hpp +++ b/include/boost/beast/http/basic_dynamic_body.hpp @@ -56,7 +56,7 @@ struct basic_dynamic_body return v.size(); } - /** The algorithm for serializing the body + /** The algorithm for parsing the body Meets the requirements of @b BodyReader. */ @@ -64,51 +64,13 @@ struct basic_dynamic_body using reader = implementation_defined; #else class reader - { - DynamicBuffer const& body_; - - public: - using const_buffers_type = - typename DynamicBuffer::const_buffers_type; - - template - explicit - reader(message const& m) - : body_(m.body()) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return {{body_.data(), false}}; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BOOST_BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer { value_type& body_; public: template explicit - writer(message& msg) : body_(msg.body()) { @@ -160,6 +122,44 @@ struct basic_dynamic_body } }; #endif + + /** The algorithm for serializing the body + + Meets the requirements of @b BodyWriter. + */ +#if BOOST_BEAST_DOXYGEN + using writer = implementation_defined; +#else + class writer + { + DynamicBuffer const& body_; + + public: + using const_buffers_type = + typename DynamicBuffer::const_buffers_type; + + template + explicit + writer(message const& m) + : body_(m.body()) + { + } + + void + init(error_code& ec) + { + ec.assign(0, ec.category()); + } + + boost::optional> + get(error_code& ec) + { + ec.assign(0, ec.category()); + return {{body_.data(), false}}; + } + }; +#endif }; } // http diff --git a/include/boost/beast/http/basic_file_body.hpp b/include/boost/beast/http/basic_file_body.hpp index 22fb91fc..cec72a8f 100644 --- a/include/boost/beast/http/basic_file_body.hpp +++ b/include/boost/beast/http/basic_file_body.hpp @@ -51,10 +51,10 @@ struct basic_file_body /// The type of File this body uses using file_type = File; - // Algorithm for retrieving buffers when serializing. + // Algorithm for storing buffers when parsing. class reader; - // Algorithm for storing buffers when parsing. + // Algorithm for retrieving buffers when serializing. class writer; // The type of the @ref message::body member. @@ -225,7 +225,7 @@ size(value_type const& body) to extract the buffers representing the body. */ template -class basic_file_body::reader +class basic_file_body::writer { value_type& body_; // The body we are reading from std::uint64_t remain_; // The number of unread bytes @@ -239,8 +239,8 @@ public: // Constructor. // - // `m` holds the message we are sending, which will - // always have the `file_body` as the body type. + // `m` holds the message we are serializing, which will + // always have the `basic_file_body` as the body type. // // Note that the message is passed by non-const reference. // This is intentional, because reading from the file @@ -248,7 +248,7 @@ public: // operation logically not-const (although it is bitwise // const). // - // The BodyReader concept allows the reader to choose + // The BodyWriter concept allows the writer to choose // whether to take the message by const reference or // non-const reference. Depending on the choice, a // serializer constructed using that body type will @@ -262,13 +262,13 @@ public: // a time. // template - reader(message< + writer(message< isRequest, basic_file_body, Fields>& m); // Initializer // // This is called before the body is serialized and - // gives the reader a chance to do something that might + // gives the writer a chance to do something that might // need to return an error code. // void @@ -295,8 +295,8 @@ public: template template basic_file_body:: -reader:: -reader(message& m) +writer:: +writer(message& m) : body_(m.body()) { // The file must already be open @@ -310,7 +310,7 @@ reader(message& m) template void basic_file_body:: -reader:: +writer:: init(error_code& ec) { // The error_code specification requires that we @@ -329,7 +329,7 @@ init(error_code& ec) template auto basic_file_body:: -reader:: +writer:: get(error_code& ec) -> boost::optional> { @@ -389,7 +389,7 @@ get(error_code& ec) -> to store incoming buffers representing the body. */ template -class basic_file_body::writer +class basic_file_body::reader { value_type& body_; // The body we are writing to @@ -399,17 +399,17 @@ public: // This is called after the header is parsed and // indicates that a non-zero sized body may be present. // `m` holds the message we are receiving, which will - // always have the `file_body` as the body type. + // always have the `basic_file_body` as the body type. // template explicit - writer( + reader( message& m); // Initializer // // This is called before the body is parsed and - // gives the writer a chance to do something that might + // gives the reader a chance to do something that might // need to return an error code. It informs us of // the payload size (`content_length`) which we can // optionally use for optimization. @@ -440,14 +440,14 @@ public: //[example_http_file_body_6 -// We don't do much in the writer constructor since the +// We don't do much in the reader constructor since the // file is already open. // template template basic_file_body:: -writer:: -writer(message& m) +reader:: +reader(message& m) : body_(m.body()) { } @@ -455,7 +455,7 @@ writer(message& m) template void basic_file_body:: -writer:: +reader:: init( boost::optional const& content_length, error_code& ec) @@ -482,7 +482,7 @@ template template std::size_t basic_file_body:: -writer:: +reader:: put(ConstBufferSequence const& buffers, error_code& ec) { // This function must return the total number of @@ -513,7 +513,7 @@ put(ConstBufferSequence const& buffers, error_code& ec) template void basic_file_body:: -writer:: +reader:: finish(error_code& ec) { // This has to be cleared before returning, to diff --git a/include/boost/beast/http/buffer_body.hpp b/include/boost/beast/http/buffer_body.hpp index 82b2b4b4..675ea947 100644 --- a/include/boost/beast/http/buffer_body.hpp +++ b/include/boost/beast/http/buffer_body.hpp @@ -91,7 +91,7 @@ struct buffer_body bool more = true; }; - /** The algorithm for serializing the body + /** The algorithm for parsing the body Meets the requirements of @b BodyReader. */ @@ -99,6 +99,64 @@ struct buffer_body using reader = implementation_defined; #else class reader + { + value_type& body_; + + public: + template + explicit + reader(message& m) + : body_(m.body()) + { + } + + void + init(boost::optional const&, error_code& ec) + { + ec.assign(0, ec.category()); + } + + template + std::size_t + put(ConstBufferSequence const& buffers, + error_code& ec) + { + using boost::asio::buffer_size; + using boost::asio::buffer_copy; + if(! body_.data) + { + ec = error::need_buffer; + return 0; + } + auto const bytes_transferred = + buffer_copy(boost::asio::buffer( + body_.data, body_.size), buffers); + body_.data = reinterpret_cast( + body_.data) + bytes_transferred; + body_.size -= bytes_transferred; + if(bytes_transferred == buffer_size(buffers)) + ec.assign(0, ec.category()); + else + ec = error::need_buffer; + return bytes_transferred; + } + + void + finish(error_code& ec) + { + ec.assign(0, ec.category()); + } + }; +#endif + + /** The algorithm for serializing the body + + Meets the requirements of @b BodyWriter. + */ +#if BOOST_BEAST_DOXYGEN + using writer = implementation_defined; +#else + class writer { bool toggle_ = false; value_type const& body_; @@ -109,7 +167,7 @@ struct buffer_body template explicit - reader(message const& msg) : body_(msg.body()) { @@ -153,64 +211,6 @@ struct buffer_body } }; #endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BOOST_BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer - { - value_type& body_; - - public: - template - explicit - writer(message& m) - : body_(m.body()) - { - } - - void - init(boost::optional const&, error_code& ec) - { - ec.assign(0, ec.category()); - } - - template - std::size_t - put(ConstBufferSequence const& buffers, - error_code& ec) - { - using boost::asio::buffer_size; - using boost::asio::buffer_copy; - if(! body_.data) - { - ec = error::need_buffer; - return 0; - } - auto const bytes_transferred = - buffer_copy(boost::asio::buffer( - body_.data, body_.size), buffers); - body_.data = reinterpret_cast( - body_.data) + bytes_transferred; - body_.size -= bytes_transferred; - if(bytes_transferred == buffer_size(buffers)) - ec.assign(0, ec.category()); - else - ec = error::need_buffer; - return bytes_transferred; - } - - void - finish(error_code& ec) - { - ec.assign(0, ec.category()); - } - }; -#endif }; #if ! BOOST_BEAST_DOXYGEN diff --git a/include/boost/beast/http/empty_body.hpp b/include/boost/beast/http/empty_body.hpp index 32c46a9c..1845a229 100644 --- a/include/boost/beast/http/empty_body.hpp +++ b/include/boost/beast/http/empty_body.hpp @@ -52,7 +52,7 @@ struct empty_body return 0; } - /** The algorithm for serializing the body + /** The algorithm for parsing the body Meets the requirements of @b BodyReader. */ @@ -61,43 +61,9 @@ struct empty_body #else struct reader { - using const_buffers_type = - boost::asio::null_buffers; - template explicit - reader(message const&) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return boost::none; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BOOST_BEAST_DOXYGEN - using writer = implementation_defined; -#else - struct writer - { - template - explicit - writer(message&) + reader(message&) { } @@ -123,6 +89,40 @@ struct empty_body } }; #endif + + /** The algorithm for serializing the body + + Meets the requirements of @b BodyWriter. + */ +#if BOOST_BEAST_DOXYGEN + using writer = implementation_defined; +#else + struct writer + { + using const_buffers_type = + boost::asio::null_buffers; + + template + explicit + writer(message const&) + { + } + + void + init(error_code& ec) + { + ec.assign(0, ec.category()); + } + + boost::optional> + get(error_code& ec) + { + ec.assign(0, ec.category()); + return boost::none; + } + }; +#endif }; } // http diff --git a/include/boost/beast/http/impl/file_body_win32.ipp b/include/boost/beast/http/impl/file_body_win32.ipp index 80a3f1d0..eb91d6a7 100644 --- a/include/boost/beast/http/impl/file_body_win32.ipp +++ b/include/boost/beast/http/impl/file_body_win32.ipp @@ -42,15 +42,15 @@ struct basic_file_body { using file_type = file_win32; - class reader; class writer; + class reader; //-------------------------------------------------------------------------- class value_type { - friend class reader; friend class writer; + friend class reader; friend struct basic_file_body; template @@ -100,7 +100,7 @@ struct basic_file_body //-------------------------------------------------------------------------- - class reader + class writer { template friend class detail::write_some_win32_op; @@ -123,7 +123,7 @@ struct basic_file_body boost::asio::const_buffer; template - reader(message, Fields>& m) : body_(m.body()) { @@ -160,14 +160,14 @@ struct basic_file_body //-------------------------------------------------------------------------- - class writer + class reader { value_type& body_; public: template explicit - writer(message& m) + reader(message& m) : body_(m.body()) { } diff --git a/include/boost/beast/http/impl/parser.ipp b/include/boost/beast/http/impl/parser.ipp index 476d537d..99745da3 100644 --- a/include/boost/beast/http/impl/parser.ipp +++ b/include/boost/beast/http/impl/parser.ipp @@ -44,7 +44,7 @@ parser(parser&& other, , m_(other.release(), std::forward(args)...) , wr_(m_) { - if(other.wr_inited_) + if(other.rd_inited_) BOOST_THROW_EXCEPTION(std::invalid_argument{ "moved-from parser has a body"}); } diff --git a/include/boost/beast/http/impl/read.ipp b/include/boost/beast/http/impl/read.ipp index 053a26c5..6d80ead0 100644 --- a/include/boost/beast/http/impl/read.ipp +++ b/include/boost/beast/http/impl/read.ipp @@ -738,8 +738,8 @@ read( "DynamicBuffer requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_writer::value, - "BodyWriter requirements not met"); + static_assert(is_body_reader::value, + "BodyReader requirements not met"); error_code ec; auto const bytes_transferred = read(stream, buffer, msg, ec); @@ -766,8 +766,8 @@ read( "DynamicBuffer requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_writer::value, - "BodyWriter requirements not met"); + static_assert(is_body_reader::value, + "BodyReader requirements not met"); parser p{std::move(msg)}; p.eager(true); auto const bytes_transferred = @@ -798,8 +798,8 @@ async_read( "DynamicBuffer requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_writer::value, - "BodyWriter requirements not met"); + static_assert(is_body_reader::value, + "BodyReader requirements not met"); boost::asio::async_completion< ReadHandler, void(error_code, std::size_t)> init{handler}; diff --git a/include/boost/beast/http/impl/write.ipp b/include/boost/beast/http/impl/write.ipp index dfd88840..9d5be277 100644 --- a/include/boost/beast/http/impl/write.ipp +++ b/include/boost/beast/http/impl/write.ipp @@ -499,8 +499,8 @@ write_some( "SyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); error_code ec; auto const bytes_transferred = write_some(stream, sr, ec); @@ -522,8 +522,8 @@ write_some( "SyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); return detail::write_some(stream, sr, ec); } @@ -543,8 +543,8 @@ async_write_some( "AsyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); return detail::async_write_some(stream, sr, std::forward(handler)); } @@ -562,8 +562,8 @@ write_header(SyncWriteStream& stream, "SyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); error_code ec; auto const bytes_transferred = write_header(stream, sr, ec); @@ -585,8 +585,8 @@ write_header( "SyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); sr.split(true); std::size_t bytes_transferred = 0; if(! sr.is_header_done()) @@ -626,8 +626,8 @@ async_write_header( "AsyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); sr.split(true); boost::asio::async_completion< WriteHandler, @@ -703,8 +703,8 @@ async_write( "AsyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); sr.split(false); boost::asio::async_completion< WriteHandler, @@ -733,8 +733,8 @@ write( "SyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); error_code ec; auto const bytes_transferred = write(stream, msg, ec); @@ -756,8 +756,8 @@ write( "SyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); serializer sr{msg}; return write(stream, sr, ec); } @@ -778,8 +778,8 @@ async_write( "AsyncWriteStream requirements not met"); static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); boost::asio::async_completion< WriteHandler, void(error_code, std::size_t)> init{handler}; @@ -860,8 +860,8 @@ operator<<(std::ostream& os, { static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); serializer sr{msg}; error_code ec; detail::write_ostream_lambda f{os, sr}; diff --git a/include/boost/beast/http/parser.hpp b/include/boost/beast/http/parser.hpp index 59a7b14f..47e10035 100644 --- a/include/boost/beast/http/parser.hpp +++ b/include/boost/beast/http/parser.hpp @@ -53,8 +53,8 @@ class parser static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_writer::value, - "BodyWriter requirements not met"); + static_assert(is_body_reader::value, + "BodyReader requirements not met"); template friend class parser; @@ -63,8 +63,8 @@ class parser parser>; message> m_; - typename Body::writer wr_; - bool wr_inited_ = false; + typename Body::reader wr_; + bool rd_inited_ = false; std::function::value); // Can't set the callback after receiving any chunk data! - BOOST_ASSERT(! wr_inited_); + BOOST_ASSERT(! rd_inited_); cb_h_ = std::ref(cb); } @@ -295,7 +295,7 @@ public: BOOST_STATIC_ASSERT(! std::is_const::value); // Can't set the callback after receiving any chunk data! - BOOST_ASSERT(! wr_inited_); + BOOST_ASSERT(! rd_inited_); cb_b_ = std::ref(cb); } @@ -377,7 +377,7 @@ private: error_code& ec) { wr_.init(content_length, ec); - wr_inited_ = true; + rd_inited_ = true; } std::size_t diff --git a/include/boost/beast/http/serializer.hpp b/include/boost/beast/http/serializer.hpp index ee5ace09..50e58185 100644 --- a/include/boost/beast/http/serializer.hpp +++ b/include/boost/beast/http/serializer.hpp @@ -60,22 +60,22 @@ public: static_assert(is_body::value, "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); /** The type of message this serializer uses This may be const or non-const depending on the - implementation of the corresponding @b BodyReader. + implementation of the corresponding @b BodyWriter. */ #if BOOST_BEAST_DOXYGEN using value_type = implementation_defined; #else using value_type = typename std::conditional< - std::is_constructible&>::value && - ! std::is_constructible const&>::value, message, message const>::type; @@ -111,7 +111,7 @@ private: void do_visit(error_code& ec, Visit& visit); - using reader = typename Body::reader; + using writer = typename Body::writer; using cb1_t = buffers_suffix; // header @@ -119,11 +119,11 @@ private: using cb2_t = buffers_suffix>; // body + typename writer::const_buffers_type>>; // body using pcb2_t = buffers_prefix_view; using cb3_t = buffers_suffix< - typename reader::const_buffers_type>; // body + typename writer::const_buffers_type>; // body using pcb3_t = buffers_prefix_view; using cb4_t = buffers_suffix>; // crlf using pcb4_t = buffers_prefix_view; @@ -139,7 +139,7 @@ private: detail::chunk_size, // chunk-header boost::asio::const_buffer, // chunk-ext chunk_crlf, // crlf - typename reader::const_buffers_type, // body + typename writer::const_buffers_type, // body chunk_crlf>>; // crlf using pcb5_t = buffers_prefix_view; @@ -147,7 +147,7 @@ private: detail::chunk_size, // chunk-header boost::asio::const_buffer, // chunk-size chunk_crlf, // crlf - typename reader::const_buffers_type, // body + typename writer::const_buffers_type, // body chunk_crlf, // crlf boost::asio::const_buffer, // chunk-final boost::asio::const_buffer, // trailers @@ -159,7 +159,7 @@ private: detail::chunk_size, // chunk-size boost::asio::const_buffer, // chunk-ext chunk_crlf, // crlf - typename reader::const_buffers_type, // body + typename writer::const_buffers_type, // body chunk_crlf, // crlf boost::asio::const_buffer, // chunk-final boost::asio::const_buffer, // trailers @@ -173,7 +173,7 @@ private: using pcb8_t = buffers_prefix_view; value_type& m_; - reader rd_; + writer rd_; boost::optional frd_; beast::detail::variant< cb1_t, cb2_t, cb3_t, cb4_t, @@ -210,7 +210,7 @@ public: the type of Body used, this may or may not be a `const` reference. @note This function participates in overload resolution only if - Body::reader is constructible from a `const` message reference. + Body::writer is constructible from a `const` message reference. */ explicit serializer(value_type& msg); @@ -336,17 +336,17 @@ public: void consume(std::size_t n); - /** Provides low-level access to the associated @b BodyReader + /** Provides low-level access to the associated @b BodyWriter - This function provides access to the instance of the reader + This function provides access to the instance of the writer associated with the body and created by the serializer upon construction. The behavior of accessing this object - is defined by the specification of the particular reader + is defined by the specification of the particular writer and its associated body. - @return A reference to the reader. + @return A reference to the writer. */ - reader& + writer& reader_impl() { return rd_; diff --git a/include/boost/beast/http/span_body.hpp b/include/boost/beast/http/span_body.hpp index 9af836af..6282ecc6 100644 --- a/include/boost/beast/http/span_body.hpp +++ b/include/boost/beast/http/span_body.hpp @@ -59,7 +59,7 @@ public: return body.size(); } - /** The algorithm for serializing the body + /** The algorithm for parsing the body Meets the requirements of @b BodyReader. */ @@ -67,55 +67,13 @@ public: using reader = implementation_defined; #else class reader - { - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffer; - - template - explicit - reader(message const& msg) - : body_(msg.body()) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return {{ - { body_.data(), - body_.size() * sizeof(typename - value_type::value_type)}, - false}}; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BOOST_BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer { value_type& body_; public: template explicit - writer(message& m) : body_(m.body()) { @@ -162,6 +120,48 @@ public: } }; #endif + + /** The algorithm for serializing the body + + Meets the requirements of @b BodyWriter. + */ +#if BOOST_BEAST_DOXYGEN + using writer = implementation_defined; +#else + class writer + { + value_type const& body_; + + public: + using const_buffers_type = + boost::asio::const_buffer; + + template + explicit + writer(message const& msg) + : body_(msg.body()) + { + } + + void + init(error_code& ec) + { + ec.assign(0, ec.category()); + } + + boost::optional> + get(error_code& ec) + { + ec.assign(0, ec.category()); + return {{ + { body_.data(), + body_.size() * sizeof(typename + value_type::value_type)}, + false}}; + } + }; +#endif }; } // http diff --git a/include/boost/beast/http/string_body.hpp b/include/boost/beast/http/string_body.hpp index 28a337b7..7c9bb6d6 100644 --- a/include/boost/beast/http/string_body.hpp +++ b/include/boost/beast/http/string_body.hpp @@ -67,7 +67,7 @@ public: return body.size(); } - /** The algorithm for serializing the body + /** The algorithm for parsing the body Meets the requirements of @b BodyReader. */ @@ -75,52 +75,13 @@ public: using reader = implementation_defined; #else class reader - { - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffer; - - template - explicit - reader(message const& msg) - : body_(msg.body()) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return {{const_buffers_type{ - body_.data(), body_.size()}, false}}; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BOOST_BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer { value_type& body_; public: template explicit - writer(message& m) : body_(m.body()) { @@ -188,6 +149,45 @@ public: } }; #endif + + /** The algorithm for serializing the body + + Meets the requirements of @b BodyWriter. + */ +#if BOOST_BEAST_DOXYGEN + using writer = implementation_defined; +#else + class writer + { + value_type const& body_; + + public: + using const_buffers_type = + boost::asio::const_buffer; + + template + explicit + writer(message const& msg) + : body_(msg.body()) + { + } + + void + init(error_code& ec) + { + ec.assign(0, ec.category()); + } + + boost::optional> + get(error_code& ec) + { + ec.assign(0, ec.category()); + return {{const_buffers_type{ + body_.data(), body_.size()}, false}}; + } + }; +#endif }; /// A @b Body using `std::string` diff --git a/include/boost/beast/http/type_traits.hpp b/include/boost/beast/http/type_traits.hpp index 7b2fd4d7..f90f16ff 100644 --- a/include/boost/beast/http/type_traits.hpp +++ b/include/boost/beast/http/type_traits.hpp @@ -57,7 +57,7 @@ using is_body = detail::has_value_type; @li `T` has a nested type named `reader` - @li The nested type meets the requirements of @b BodyReader. + @li The nested type meets the requirements of @b BodyWriter. @tparam T The body type to test. @@ -65,55 +65,9 @@ using is_body = detail::has_value_type; @code template void check_can_serialize(message const&) - { - static_assert(is_body_reader::value, - "Cannot serialize Body, no reader"); - } - @endcode -*/ -#if BOOST_BEAST_DOXYGEN -template -struct is_body_reader : std::integral_constant {}; -#else -template -struct is_body_reader : std::false_type {}; - -template -struct is_body_reader().init(std::declval()), - std::declval>&>() = - std::declval().get(std::declval()), - (void)0)>> : std::integral_constant::value && - std::is_constructible&>::value && - std::is_constructible&>::value - > {}; -#endif - -/** Determine if a @b Body type has a writer. - - This metafunction is equivalent to `std::true_type` if: - - @li `T` has a nested type named `writer` - - @li The nested type meets the requirements of @b BodyWriter. - - @tparam T The body type to test. - - @par Example - @code - template - void check_can_parse(message&) { static_assert(is_body_writer::value, - "Cannot parse Body, no writer"); + "Cannot serialize Body, no reader"); } @endcode */ @@ -125,20 +79,66 @@ template struct is_body_writer : std::false_type {}; template -struct is_body_writer().init( +struct is_body_writer().init(std::declval()), + std::declval>&>() = + std::declval().get(std::declval()), + (void)0)>> : std::integral_constant::value && + std::is_constructible&>::value && + std::is_constructible&>::value + > {}; +#endif + +/** Determine if a @b Body type has a reader. + + This metafunction is equivalent to `std::true_type` if: + + @li `T` has a nested type named `reader` + + @li The nested type meets the requirements of @b BodyReader. + + @tparam T The body type to test. + + @par Example + @code + template + void check_can_parse(message&) + { + static_assert(is_body_reader::value, + "Cannot parse Body, no reader"); + } + @endcode +*/ +#if BOOST_BEAST_DOXYGEN +template +struct is_body_reader : std::integral_constant {}; +#else +template +struct is_body_reader : std::false_type {}; + +template +struct is_body_reader().init( boost::optional(), std::declval()), std::declval() = - std::declval().put( + std::declval().put( std::declval(), std::declval()), - std::declval().finish( + std::declval().finish( std::declval()), (void)0)>> : std::integral_constant&>::value && - std::is_constructible&>::value > { diff --git a/include/boost/beast/http/vector_body.hpp b/include/boost/beast/http/vector_body.hpp index 91378917..f1729335 100644 --- a/include/boost/beast/http/vector_body.hpp +++ b/include/boost/beast/http/vector_body.hpp @@ -62,7 +62,7 @@ public: return body.size(); } - /** The algorithm for serializing the body + /** The algorithm for parsing the body Meets the requirements of @b BodyReader. */ @@ -70,52 +70,13 @@ public: using reader = implementation_defined; #else class reader - { - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffer; - - template - explicit - reader(message const& msg) - : body_(msg.body()) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return {{const_buffers_type{ - body_.data(), body_.size()}, false}}; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BOOST_BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer { value_type& body_; public: template explicit - writer(message& m) : body_(m.body()) { @@ -177,6 +138,45 @@ public: } }; #endif + + /** The algorithm for serializing the body + + Meets the requirements of @b BodyWriter. + */ +#if BOOST_BEAST_DOXYGEN + using writer = implementation_defined; +#else + class writer + { + value_type const& body_; + + public: + using const_buffers_type = + boost::asio::const_buffer; + + template + explicit + writer(message const& msg) + : body_(msg.body()) + { + } + + void + init(error_code& ec) + { + ec.assign(0, ec.category()); + } + + boost::optional> + get(error_code& ec) + { + ec.assign(0, ec.category()); + return {{const_buffers_type{ + body_.data(), body_.size()}, false}}; + } + }; +#endif }; } // http diff --git a/test/beast/http/empty_body.cpp b/test/beast/http/empty_body.cpp index 720c544f..5caa0d64 100644 --- a/test/beast/http/empty_body.cpp +++ b/test/beast/http/empty_body.cpp @@ -15,8 +15,8 @@ namespace beast { namespace http { BOOST_STATIC_ASSERT(is_body::value); -BOOST_STATIC_ASSERT(is_body_reader::value); BOOST_STATIC_ASSERT(is_body_writer::value); +BOOST_STATIC_ASSERT(is_body_reader::value); } // http } // beast diff --git a/test/beast/http/serializer.cpp b/test/beast/http/serializer.cpp index 7e35f253..d4cab4ad 100644 --- a/test/beast/http/serializer.cpp +++ b/test/beast/http/serializer.cpp @@ -24,13 +24,13 @@ public: { struct value_type{}; - struct reader + struct writer { using const_buffers_type = boost::asio::const_buffer; template - reader(message const&); + writer(message const&); void init(error_code& ec); @@ -44,13 +44,13 @@ public: { struct value_type{}; - struct reader + struct writer { using const_buffers_type = boost::asio::const_buffer; template - reader(message&); + writer(message&); void init(error_code& ec); diff --git a/test/beast/http/span_body.cpp b/test/beast/http/span_body.cpp index 55d5149e..d76ddd06 100644 --- a/test/beast/http/span_body.cpp +++ b/test/beast/http/span_body.cpp @@ -34,7 +34,7 @@ struct span_body_test BEAST_EXPECT(req.body().size() == 3); BEAST_EXPECT(B::size(req.body()) == 3); - B::reader r{req}; + B::writer r{req}; error_code ec; r.init(ec); BEAST_EXPECTS(! ec, ec.message()); @@ -50,7 +50,7 @@ struct span_body_test using B = span_body; request req; req.body() = span{buf, sizeof(buf)}; - B::writer w{req}; + B::reader w{req}; error_code ec; w.init(boost::none, ec); BEAST_EXPECTS(! ec, ec.message()); diff --git a/test/beast/http/string_body.cpp b/test/beast/http/string_body.cpp index 48efe517..08d08ee6 100644 --- a/test/beast/http/string_body.cpp +++ b/test/beast/http/string_body.cpp @@ -15,8 +15,8 @@ namespace beast { namespace http { BOOST_STATIC_ASSERT(is_body::value); -BOOST_STATIC_ASSERT(is_body_reader::value); BOOST_STATIC_ASSERT(is_body_writer::value); +BOOST_STATIC_ASSERT(is_body_reader::value); } // http } // beast diff --git a/test/beast/http/type_traits.cpp b/test/beast/http/type_traits.cpp index c7e654ec..e1a507bf 100644 --- a/test/beast/http/type_traits.cpp +++ b/test/beast/http/type_traits.cpp @@ -17,11 +17,11 @@ namespace boost { namespace beast { namespace http { -BOOST_STATIC_ASSERT(! is_body_reader::value); +BOOST_STATIC_ASSERT(! is_body_writer::value); -BOOST_STATIC_ASSERT(is_body_reader::value); +BOOST_STATIC_ASSERT(is_body_writer::value); -BOOST_STATIC_ASSERT(! is_body_writer::value); +BOOST_STATIC_ASSERT(! is_body_reader::value); namespace { diff --git a/test/beast/http/vector_body.cpp b/test/beast/http/vector_body.cpp index 312bd1aa..cda69795 100644 --- a/test/beast/http/vector_body.cpp +++ b/test/beast/http/vector_body.cpp @@ -15,8 +15,8 @@ namespace beast { namespace http { BOOST_STATIC_ASSERT(is_body>::value); -BOOST_STATIC_ASSERT(is_body_reader>::value); BOOST_STATIC_ASSERT(is_body_writer>::value); +BOOST_STATIC_ASSERT(is_body_reader>::value); } // http } // beast diff --git a/test/beast/http/write.cpp b/test/beast/http/write.cpp index bcd91952..6e72782e 100644 --- a/test/beast/http/write.cpp +++ b/test/beast/http/write.cpp @@ -38,7 +38,7 @@ public: { using value_type = std::string; - class reader + class writer { value_type const& body_; @@ -48,7 +48,7 @@ public: template explicit - reader(message const& msg) : body_(msg.body()) { @@ -82,7 +82,7 @@ public: bool mutable read = false; }; - class reader + class writer { int step_ = 0; value_type const& body_; @@ -93,7 +93,7 @@ public: template explicit - reader(message const& msg) : body_(msg.body()) { @@ -195,11 +195,11 @@ public: struct fail_body { - class reader; + class writer; class value_type { - friend class reader; + friend class writer; std::string s_; test::fail_counter& fc_; @@ -219,7 +219,7 @@ public: } }; - class reader + class writer { std::size_t n_ = 0; value_type const& body_; @@ -230,7 +230,7 @@ public: template explicit - reader(message const& msg) : body_(msg.body()) { diff --git a/test/doc/exemplars.cpp b/test/doc/exemplars.cpp index 336e99bb..bc4e7e51 100644 --- a/test/doc/exemplars.cpp +++ b/test/doc/exemplars.cpp @@ -19,8 +19,8 @@ namespace boost { namespace beast { namespace http { -class BodyReader; class BodyWriter; +class BodyReader; //[concept_Body @@ -29,10 +29,10 @@ struct Body // The type of message::body when used struct value_type; - /// The algorithm used for extracting buffers + /// The algorithm used during parsing class reader; - /// The algorithm used for inserting buffers + /// The algorithm used during serialization class writer; /// Returns the body's payload size @@ -45,27 +45,27 @@ static_assert(is_body::value, ""); //] -struct Body_BodyReader { +struct Body_BodyWriter { struct value_type{}; -//[concept_BodyReader +//[concept_BodyWriter -struct BodyReader +struct BodyWriter { public: /// The type of buffer returned by `get`. using const_buffers_type = boost::asio::const_buffer; - /** Construct the reader. + /** Construct the writer. - @param msg The message whose body is to be retrieved. + @param msg The message whose body is to be serialized. @param ec Set to the error, if any occurred. */ template explicit - BodyReader(message const& msg); + BodyWriter(message const& msg); - /** Initialize the reader + /** Initialize the writer. This is called after construction and before the first call to `get`. The message is valid and complete upon @@ -109,26 +109,26 @@ public: }; //] - using reader = BodyReader; + using writer = BodyWriter; }; -static_assert(is_body_reader::value, ""); +static_assert(is_body_writer::value, ""); -struct Body_BodyWriter { +struct Body_BodyReader { struct value_type{}; -//[concept_BodyWriter +//[concept_BodyReader -struct BodyWriter +struct BodyReader { - /** Construct the writer. + /** Construct the reader. - @param msg The message whose body is to be stored. + @param msg The message whose body is to be parsed. */ template explicit - BodyWriter(message& msg); + BodyReader(message& msg); - /** Initialize the writer + /** Initialize the reader. This is called after construction and before the first call to `put`. The message is valid and complete upon @@ -180,10 +180,10 @@ struct BodyWriter }; //] - using writer = BodyWriter; + using reader = BodyReader; }; -static_assert(is_body_writer::value, ""); +static_assert(is_body_reader::value, ""); //[concept_Fields diff --git a/test/doc/http_snippets.cpp b/test/doc/http_snippets.cpp index a59a2456..8985fa12 100644 --- a/test/doc/http_snippets.cpp +++ b/test/doc/http_snippets.cpp @@ -299,7 +299,7 @@ void fxx() { the @b SyncWriteStream concept. @param m The message to send. The Body type must support - the @b BodyReader concept. + the @b BodyWriter concept. */ template< class SyncWriteStream, @@ -312,8 +312,8 @@ send( // Check the template types static_assert(is_sync_write_stream::value, "SyncWriteStream requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); + static_assert(is_body_writer::value, + "BodyWriter requirements not met"); // Create the instance of serializer for the message serializer sr{m};