2017-05-08 12:41:45 -07:00
|
|
|
//
|
2019-02-21 07:00:31 -08:00
|
|
|
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-05-08 12:41:45 -07:00
|
|
|
//
|
|
|
|
|
// 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)
|
|
|
|
|
//
|
2017-07-20 13:40:34 -07:00
|
|
|
// Official repository: https://github.com/boostorg/beast
|
|
|
|
|
//
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
#ifndef BOOST_BEAST_HTTP_EMPTY_BODY_HPP
|
|
|
|
|
#define BOOST_BEAST_HTTP_EMPTY_BODY_HPP
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-10-10 07:49:03 -07:00
|
|
|
#include <boost/beast/core/detail/config.hpp>
|
2017-07-20 13:40:34 -07:00
|
|
|
#include <boost/beast/http/error.hpp>
|
|
|
|
|
#include <boost/beast/http/message.hpp>
|
2017-05-08 12:41:45 -07:00
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
namespace boost {
|
2017-05-08 12:41:45 -07:00
|
|
|
namespace beast {
|
|
|
|
|
namespace http {
|
|
|
|
|
|
2019-03-05 12:05:00 -08:00
|
|
|
/** An empty <em>Body</em>
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-06-04 15:05:23 -07:00
|
|
|
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.
|
2017-05-08 12:41:45 -07:00
|
|
|
|
2017-07-08 17:11:49 -07:00
|
|
|
The Content-Length of this body is always 0.
|
2017-05-08 12:41:45 -07:00
|
|
|
*/
|
|
|
|
|
struct empty_body
|
|
|
|
|
{
|
2017-07-08 17:11:49 -07:00
|
|
|
/** 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.
|
|
|
|
|
*/
|
2017-05-08 12:41:45 -07:00
|
|
|
struct value_type
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-08 17:11:49 -07:00
|
|
|
/** 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.
|
|
|
|
|
*/
|
2017-06-05 21:11:33 -07:00
|
|
|
static
|
|
|
|
|
std::uint64_t
|
2017-06-19 15:37:39 -07:00
|
|
|
size(value_type)
|
2017-06-05 21:11:33 -07:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-30 17:08:52 -07:00
|
|
|
/** The algorithm for parsing the body
|
2017-07-08 17:11:49 -07:00
|
|
|
|
2019-03-05 12:05:00 -08:00
|
|
|
Meets the requirements of <em>BodyReader</em>.
|
2017-07-08 17:11:49 -07:00
|
|
|
*/
|
2017-07-20 13:40:34 -07:00
|
|
|
#if BOOST_BEAST_DOXYGEN
|
2018-11-11 21:53:13 -08:00
|
|
|
using reader = __implementation_defined__;
|
2017-05-08 12:41:45 -07:00
|
|
|
#else
|
2017-05-28 09:05:29 -07:00
|
|
|
struct reader
|
2017-05-08 12:41:45 -07:00
|
|
|
{
|
|
|
|
|
template<bool isRequest, class Fields>
|
|
|
|
|
explicit
|
2017-11-13 23:34:14 +01:00
|
|
|
reader(header<isRequest, Fields>&, value_type&)
|
2017-07-07 20:08:52 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
init(boost::optional<std::uint64_t> const&, error_code& ec)
|
2017-05-31 08:01:55 -07:00
|
|
|
{
|
2019-01-20 09:50:43 -08:00
|
|
|
ec = {};
|
2017-05-31 08:01:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class ConstBufferSequence>
|
2017-07-02 06:32:19 -07:00
|
|
|
std::size_t
|
2017-05-31 08:01:55 -07:00
|
|
|
put(ConstBufferSequence const&,
|
|
|
|
|
error_code& ec)
|
|
|
|
|
{
|
2017-06-04 15:05:23 -07:00
|
|
|
ec = error::unexpected_body;
|
2017-07-02 06:32:19 -07:00
|
|
|
return 0;
|
2017-05-31 08:01:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2017-06-13 07:08:52 -07:00
|
|
|
finish(error_code& ec)
|
2017-05-31 08:01:55 -07:00
|
|
|
{
|
2019-01-20 09:50:43 -08:00
|
|
|
ec = {};
|
2017-05-31 08:01:55 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
#endif
|
2017-10-30 17:08:52 -07:00
|
|
|
|
|
|
|
|
/** The algorithm for serializing the body
|
|
|
|
|
|
2019-03-05 12:05:00 -08:00
|
|
|
Meets the requirements of <em>BodyWriter</em>.
|
2017-10-30 17:08:52 -07:00
|
|
|
*/
|
|
|
|
|
#if BOOST_BEAST_DOXYGEN
|
2018-11-11 21:53:13 -08:00
|
|
|
using writer = __implementation_defined__;
|
2017-10-30 17:08:52 -07:00
|
|
|
#else
|
|
|
|
|
struct writer
|
|
|
|
|
{
|
|
|
|
|
using const_buffers_type =
|
2018-11-30 14:58:38 -08:00
|
|
|
net::const_buffer;
|
2017-10-30 17:08:52 -07:00
|
|
|
|
|
|
|
|
template<bool isRequest, class Fields>
|
|
|
|
|
explicit
|
2017-11-13 23:34:14 +01:00
|
|
|
writer(header<isRequest, Fields> const&, value_type const&)
|
2017-10-30 17:08:52 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
init(error_code& ec)
|
|
|
|
|
{
|
2019-01-20 09:50:43 -08:00
|
|
|
ec = {};
|
2017-10-30 17:08:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::optional<std::pair<const_buffers_type, bool>>
|
|
|
|
|
get(error_code& ec)
|
|
|
|
|
{
|
2019-01-20 09:50:43 -08:00
|
|
|
ec = {};
|
2017-10-30 17:08:52 -07:00
|
|
|
return boost::none;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
#endif
|
2017-05-08 12:41:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // http
|
|
|
|
|
} // beast
|
2017-07-20 13:40:34 -07:00
|
|
|
} // boost
|
2017-05-08 12:41:45 -07:00
|
|
|
|
|
|
|
|
#endif
|