summaryrefslogtreecommitdiff
path: root/boost/beast/http/empty_body.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/beast/http/empty_body.hpp')
-rw-r--r--boost/beast/http/empty_body.hpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/boost/beast/http/empty_body.hpp b/boost/beast/http/empty_body.hpp
new file mode 100644
index 0000000000..1845a22992
--- /dev/null
+++ b/boost/beast/http/empty_body.hpp
@@ -0,0 +1,132 @@
+//
+// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot 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/boostorg/beast
+//
+
+#ifndef BOOST_BEAST_HTTP_EMPTY_BODY_HPP
+#define BOOST_BEAST_HTTP_EMPTY_BODY_HPP
+
+#include <boost/beast/core/detail/config.hpp>
+#include <boost/beast/http/error.hpp>
+#include <boost/beast/http/message.hpp>
+#include <boost/optional.hpp>
+
+namespace boost {
+namespace beast {
+namespace http {
+
+/** An empty @b Body
+
+ This body is used to represent messages which do not have a
+ message body. If this body is used with a parser, and the
+ parser encounters octets corresponding to a message body,
+ the parser will fail with the error @ref http::unexpected_body.
+
+ The Content-Length of this body is always 0.
+*/
+struct empty_body
+{
+ /** The type of container used for the body
+
+ This determines the type of @ref message::body
+ when this body type is used with a message container.
+ */
+ struct value_type
+ {
+ };
+
+ /** Returns the payload size of the body
+
+ When this body is used with @ref message::prepare_payload,
+ the Content-Length will be set to the payload size, and
+ any chunked Transfer-Encoding will be removed.
+ */
+ static
+ std::uint64_t
+ size(value_type)
+ {
+ return 0;
+ }
+
+ /** The algorithm for parsing the body
+
+ Meets the requirements of @b BodyReader.
+ */
+#if BOOST_BEAST_DOXYGEN
+ using reader = implementation_defined;
+#else
+ struct reader
+ {
+ template<bool isRequest, class Fields>
+ explicit
+ reader(message<isRequest, empty_body, Fields>&)
+ {
+ }
+
+ void
+ init(boost::optional<std::uint64_t> const&, error_code& ec)
+ {
+ ec.assign(0, ec.category());
+ }
+
+ template<class ConstBufferSequence>
+ std::size_t
+ put(ConstBufferSequence const&,
+ error_code& ec)
+ {
+ ec = error::unexpected_body;
+ return 0;
+ }
+
+ 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
+ struct writer
+ {
+ using const_buffers_type =
+ boost::asio::null_buffers;
+
+ template<bool isRequest, class Fields>
+ explicit
+ writer(message<isRequest,
+ empty_body, Fields> const&)
+ {
+ }
+
+ void
+ init(error_code& ec)
+ {
+ ec.assign(0, ec.category());
+ }
+
+ boost::optional<std::pair<const_buffers_type, bool>>
+ get(error_code& ec)
+ {
+ ec.assign(0, ec.category());
+ return boost::none;
+ }
+ };
+#endif
+};
+
+} // http
+} // beast
+} // boost
+
+#endif