diff --git a/doc/modules/ROOT/pages/reference.adoc b/doc/modules/ROOT/pages/reference.adoc index 53811299..e2d0de29 100644 --- a/doc/modules/ROOT/pages/reference.adoc +++ b/doc/modules/ROOT/pages/reference.adoc @@ -53,10 +53,10 @@ cpp:boost::http_proto::response[response] cpp:boost::http_proto::response_base[response_base] -| **Types (2/2)** - cpp:boost::http_proto::response_parser[response_parser] +| **Types (2/2)** + cpp:boost::http_proto::response_view[response_view] cpp:boost::http_proto::serializer[serializer] @@ -71,6 +71,8 @@ cpp:boost::http_proto::static_request[static_request] cpp:boost::http_proto::static_response[static_response] +cpp:boost::http_proto::string_body[string_body] + **Functions** cpp:boost::http_proto::combine_field_values[combine_field_values] diff --git a/doc/tagfiles/boost-http_proto-doxygen.tag.xml b/doc/tagfiles/boost-http_proto-doxygen.tag.xml index fd7a6fa4..c52e205f 100644 --- a/doc/tagfiles/boost-http_proto-doxygen.tag.xml +++ b/doc/tagfiles/boost-http_proto-doxygen.tag.xml @@ -34,6 +34,7 @@ boost::http_proto::static_fields boost::http_proto::static_request boost::http_proto::static_response + boost::http_proto::string_body boost::http_proto::upgrade_protocol boost::http_proto::condition boost::http_proto::content_coding @@ -206,8 +207,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -322,8 +323,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -493,13 +494,6 @@ boost::http_proto::file boost/http_proto/file.adoc - - void - ~file - boost/http_proto/file/2destructor.adoc - - () - file& operator= @@ -735,8 +729,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -1382,8 +1376,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -1603,8 +1597,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -2077,8 +2071,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -2277,8 +2271,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -2840,8 +2834,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -3019,8 +3013,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -3219,8 +3213,8 @@ void - set_max_capacity - boost/http_proto/fields_base/set_max_capacity.adoc + set_max_capacity_in_bytes + boost/http_proto/fields_base/set_max_capacity_in_bytes.adoc (std::size_t n) @@ -3281,6 +3275,24 @@ () + + boost::http_proto::string_body + boost/http_proto/string_body.adoc + + const_iterator + begin + boost/http_proto/string_body/begin.adoc + + () + + + const_iterator + end + boost/http_proto/string_body/end.adoc + + () + + boost::http_proto::upgrade_protocol boost/http_proto/upgrade_protocol.adoc diff --git a/include/boost/http_proto.hpp b/include/boost/http_proto.hpp index 280e971c..41ffe717 100644 --- a/include/boost/http_proto.hpp +++ b/include/boost/http_proto.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include diff --git a/include/boost/http_proto/field.hpp b/include/boost/http_proto/field.hpp index fcfa0301..6e5e7c74 100644 --- a/include/boost/http_proto/field.hpp +++ b/include/boost/http_proto/field.hpp @@ -389,7 +389,7 @@ enum class field : unsigned short */ BOOST_HTTP_PROTO_DECL core::string_view -to_string(field f) noexcept; +to_string(field f); /** Return the field name constant for a header name. diff --git a/include/boost/http_proto/string_body.hpp b/include/boost/http_proto/string_body.hpp new file mode 100644 index 00000000..b7ae5c2c --- /dev/null +++ b/include/boost/http_proto/string_body.hpp @@ -0,0 +1,103 @@ +// +// Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/cppalliance/http_proto +// + +#ifndef BOOST_HTTP_PROTO_STRING_BODY_HPP +#define BOOST_HTTP_PROTO_STRING_BODY_HPP + +#include +#include +#include +#include + +namespace boost { +namespace http_proto { + +/** A ConstBufferSequence adapter for an owned `std::string`. + + Takes ownership of a `std::string` and exposes + it via an interface conforming to the + ConstBufferSequence requirements. + + @par Example + @code + serializer sr(ctx); + response res(status::not_found); + + std::string body = + "\n" + " \n" + "

404 Not Found

\n" + "

Sorry, the page does not exist.

\n" + " \n" + "\n"; + sr.start(res, std::move(body)); + @endcode + + @see + @ref serializer. +*/ +class string_body +{ + std::string s_; + buffers::const_buffer cb_; + +public: + /// The type for each buffer. + using value_type = buffers::const_buffer; + + /// The type of a const iterator. + using const_iterator = buffers::const_buffer const*; + + string_body( + string_body&& other) noexcept + : s_(std::move(other.s_)) + , cb_(s_.data(), s_.size()) + { + other.cb_ = {}; + } + + /** Constructor. + */ + string_body( + string_body const& other) = delete; + + /** Constructor. + + @param s The string to take ownership of. + */ + string_body( + std::string s) noexcept + : s_(std::move(s)) + , cb_(s_.data(), s_.size()) + { + } + + /** Return an iterator to the beginning of the + buffer sequence. + */ + const_iterator + begin() const noexcept + { + return &cb_; + } + + /** Return an iterator to the end of the + buffer sequence. + */ + const_iterator + end() const noexcept + { + return &cb_ + 1; + } +}; + +} // http_proto +} // boost + +#endif diff --git a/include/boost/http_proto/version.hpp b/include/boost/http_proto/version.hpp index 54a7b668..7cb5a2ca 100644 --- a/include/boost/http_proto/version.hpp +++ b/include/boost/http_proto/version.hpp @@ -33,7 +33,7 @@ enum class version : char */ BOOST_HTTP_PROTO_DECL core::string_view -to_string(version v) noexcept; +to_string(version v); /** Format the version to an output stream. diff --git a/src/field.cpp b/src/field.cpp index 6bdb98a0..c1c5b64e 100644 --- a/src/field.cpp +++ b/src/field.cpp @@ -552,7 +552,7 @@ get_field_table() noexcept } // detail core::string_view -to_string(field f) noexcept +to_string(field f) { auto const& v = detail::get_field_table(); BOOST_ASSERT(static_cast(f) < v.size()); diff --git a/src/version.cpp b/src/version.cpp index ca904a0c..88e7170c 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -15,7 +15,7 @@ namespace http_proto { core::string_view to_string( - version v) noexcept + version v) { switch(v) {