Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:31

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_HTTP_EMPTY_BODY_HPP
0011 #define BOOST_BEAST_HTTP_EMPTY_BODY_HPP
0012 
0013 #include <boost/beast/core/detail/config.hpp>
0014 #include <boost/beast/http/error.hpp>
0015 #include <boost/beast/http/message.hpp>
0016 #include <boost/optional.hpp>
0017 
0018 #include <cstdint>
0019 
0020 namespace boost {
0021 namespace beast {
0022 namespace http {
0023 
0024 /** An empty <em>Body</em>
0025 
0026     This body is used to represent messages which do not have a
0027     message body. If this body is used with a parser, and the
0028     parser encounters octets corresponding to a message body,
0029     the parser will fail with the error @ref http::unexpected_body.
0030 
0031     The Content-Length of this body is always 0.
0032 */
0033 struct empty_body
0034 {
0035     /** The type of container used for the body
0036 
0037         This determines the type of @ref message::body
0038         when this body type is used with a message container.
0039     */
0040     struct value_type
0041     {
0042     };
0043 
0044     /** Returns the payload size of the body
0045 
0046         When this body is used with @ref message::prepare_payload,
0047         the Content-Length will be set to the payload size, and
0048         any chunked Transfer-Encoding will be removed.
0049     */
0050     static
0051     std::uint64_t
0052     size(value_type)
0053     {
0054         return 0;
0055     }
0056 
0057     /** The algorithm for parsing the body
0058 
0059         Meets the requirements of <em>BodyReader</em>.
0060     */
0061 #if BOOST_BEAST_DOXYGEN
0062     using reader = __implementation_defined__;
0063 #else
0064     struct reader
0065     {
0066         template<bool isRequest, class Fields>
0067         explicit
0068         reader(header<isRequest, Fields>&, value_type&)
0069         {
0070         }
0071 
0072         void
0073         init(boost::optional<std::uint64_t> const&, error_code& ec)
0074         {
0075             ec = {};
0076         }
0077 
0078         template<class ConstBufferSequence>
0079         std::size_t
0080         put(ConstBufferSequence const&,
0081             error_code& ec)
0082         {
0083             BOOST_BEAST_ASSIGN_EC(ec, error::unexpected_body);
0084             return 0;
0085         }
0086 
0087         void
0088         finish(error_code& ec)
0089         {
0090             ec = {};
0091         }
0092     };
0093 #endif
0094 
0095     /** The algorithm for serializing the body
0096 
0097         Meets the requirements of <em>BodyWriter</em>.
0098     */
0099 #if BOOST_BEAST_DOXYGEN
0100     using writer = __implementation_defined__;
0101 #else
0102     struct writer
0103     {
0104         using const_buffers_type =
0105             net::const_buffer;
0106 
0107         template<bool isRequest, class Fields>
0108         explicit
0109         writer(header<isRequest, Fields> const&, value_type const&)
0110         {
0111         }
0112 
0113         void
0114         init(error_code& ec)
0115         {
0116             ec = {};
0117         }
0118 
0119         boost::optional<std::pair<const_buffers_type, bool>>
0120         get(error_code& ec)
0121         {
0122             ec = {};
0123             return boost::none;
0124         }
0125     };
0126 #endif
0127 };
0128 
0129 } // http
0130 } // beast
0131 } // boost
0132 
0133 #endif