Files
boost_beast/include/beast/http/chunk_encode.hpp
T

75 lines
1.8 KiB
C++
Raw Normal View History

2016-04-19 20:29:16 -04:00
//
// Copyright (c) 2013-2016 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)
//
2014-11-12 16:15:33 -08:00
#ifndef BEAST_HTTP_CHUNK_ENCODE_HPP
#define BEAST_HTTP_CHUNK_ENCODE_HPP
2014-11-12 16:15:33 -08:00
2016-05-07 17:06:46 -04:00
#include <beast/core/buffer_cat.hpp>
#include <beast/http/detail/chunk_encode.hpp>
2014-11-12 16:15:33 -08:00
#include <boost/asio/buffer.hpp>
2016-09-25 12:17:32 -04:00
#include <boost/assert.hpp>
2014-11-12 16:15:33 -08:00
#include <algorithm>
#include <array>
#include <cstddef>
#include <iterator>
2015-10-07 20:46:52 -07:00
#include <type_traits>
2014-11-12 16:15:33 -08:00
namespace beast {
namespace http {
2016-05-07 17:06:46 -04:00
/** Returns a chunk-encoded ConstBufferSequence.
2014-11-12 16:15:33 -08:00
2016-05-07 17:06:46 -04:00
This returns a buffer sequence representing the
first chunk of a chunked transfer coded body.
2014-11-12 16:15:33 -08:00
2016-11-07 16:57:41 -05:00
@param fin `true` if this is the last chunk.
2014-11-12 16:15:33 -08:00
@param buffers The input buffer sequence.
2016-03-11 06:40:37 -05:00
@return A chunk-encoded ConstBufferSequence representing the input.
2016-05-07 17:06:46 -04:00
@see <a href=https://tools.ietf.org/html/rfc7230#section-4.1.3>rfc7230 section 4.1.3</a>
2014-11-12 16:15:33 -08:00
*/
2016-03-11 06:40:37 -05:00
template<class ConstBufferSequence>
#if GENERATING_DOCS
implementation_defined
#else
2016-11-08 19:00:40 -05:00
beast::detail::buffer_cat_helper<
detail::chunk_encode_delim,
2016-11-08 19:00:40 -05:00
ConstBufferSequence,
boost::asio::const_buffers_1>
2016-03-11 06:40:37 -05:00
#endif
2016-11-07 16:57:41 -05:00
chunk_encode(bool fin, ConstBufferSequence const& buffers)
2014-11-12 16:15:33 -08:00
{
2016-05-07 17:06:46 -04:00
using boost::asio::buffer_size;
return buffer_cat(
detail::chunk_encode_delim{buffer_size(buffers)},
2016-05-07 17:06:46 -04:00
buffers,
2016-11-07 16:57:41 -05:00
fin ? boost::asio::const_buffers_1{"\r\n0\r\n\r\n", 7}
: boost::asio::const_buffers_1{"\r\n", 2});
2014-11-12 16:15:33 -08:00
}
2016-11-07 16:57:41 -05:00
/** Returns a chunked encoding final chunk.
@see <a href=https://tools.ietf.org/html/rfc7230#section-4.1.3>rfc7230 section 4.1.3</a>
*/
2014-11-12 16:15:33 -08:00
inline
2016-03-11 06:40:37 -05:00
#if GENERATING_DOCS
implementation_defined
#else
2014-11-12 16:15:33 -08:00
boost::asio::const_buffers_1
2016-03-11 06:40:37 -05:00
#endif
2014-11-12 16:15:33 -08:00
chunk_encode_final()
{
2016-11-07 16:57:41 -05:00
return boost::asio::const_buffers_1{"0\r\n\r\n", 5};
2014-11-12 16:15:33 -08:00
}
} // http
} // beast
#endif