Files
boost_beast/include/boost/beast/http/empty_body.hpp

133 lines
3.0 KiB
C++
Raw Normal View History

//
2017-07-24 09:42:36 -07:00
// 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)
//
2017-07-20 13:40:34 -07:00
// Official repository: https://github.com/boostorg/beast
//
2017-07-20 13:40:34 -07:00
#ifndef BOOST_BEAST_HTTP_EMPTY_BODY_HPP
#define BOOST_BEAST_HTTP_EMPTY_BODY_HPP
2017-07-20 13:40:34 -07:00
#include <boost/beast/config.hpp>
#include <boost/beast/http/error.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/optional.hpp>
2017-07-20 13:40:34 -07:00
namespace boost {
namespace beast {
namespace http {
2017-07-08 17:11:49 -07:00
/** An empty @b Body
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-07-08 17:11:49 -07:00
The Content-Length of this body is always 0.
*/
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.
*/
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
size(value_type)
2017-06-05 21:11:33 -07:00
{
return 0;
}
2017-07-08 17:11:49 -07:00
/** The algorithm for serializing the body
Meets the requirements of @b BodyReader.
*/
2017-07-20 13:40:34 -07:00
#if BOOST_BEAST_DOXYGEN
using reader = implementation_defined;
#else
struct reader
{
using const_buffers_type =
boost::asio::null_buffers;
template<bool isRequest, class Fields>
explicit
reader(message<isRequest,
empty_body, Fields> const&)
{
}
void
init(error_code& ec)
{
2017-06-19 16:57:12 -07:00
ec.assign(0, ec.category());
}
boost::optional<std::pair<const_buffers_type, bool>>
get(error_code& ec)
{
2017-06-19 16:57:12 -07:00
ec.assign(0, ec.category());
return boost::none;
}
};
#endif
2017-07-08 17:11:49 -07:00
/** The algorithm for parsing the body
Meets the requirements of @b BodyReader.
*/
2017-07-20 13:40:34 -07:00
#if BOOST_BEAST_DOXYGEN
using writer = implementation_defined;
#else
struct writer
{
template<bool isRequest, class Fields>
explicit
writer(message<isRequest, empty_body, Fields>&)
{
}
void
init(boost::optional<std::uint64_t> const&, error_code& ec)
{
2017-06-19 16:57:12 -07:00
ec.assign(0, ec.category());
}
template<class ConstBufferSequence>
std::size_t
put(ConstBufferSequence const&,
error_code& ec)
{
2017-06-04 15:05:23 -07:00
ec = error::unexpected_body;
return 0;
}
void
2017-06-13 07:08:52 -07:00
finish(error_code& ec)
{
2017-06-19 16:57:12 -07:00
ec.assign(0, ec.category());
}
};
#endif
};
} // http
} // beast
2017-07-20 13:40:34 -07:00
} // boost
#endif