2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BEAST_HTTP_CHUNK_ENCODE_HPP
9 #define BEAST_HTTP_CHUNK_ENCODE_HPP
11 #include <beast/config.hpp>
12 #include <beast/core/buffer_cat.hpp>
13 #include <beast/http/detail/chunk_encode.hpp>
14 #include <boost/asio/buffer.hpp>
15 #include <boost/assert.hpp>
20 #include <type_traits>
25 /** Returns a chunk-encoded ConstBufferSequence.
27 This returns a buffer sequence representing the
28 first chunk of a chunked transfer coded body.
30 @param fin `true` if this is the last chunk.
32 @param buffers The input buffer sequence.
34 @return A chunk-encoded ConstBufferSequence representing the input.
36 @see <a href=https://tools.ietf.org/html/rfc7230#section-4.1.3>rfc7230 section 4.1.3</a>
38 template<class ConstBufferSequence>
40 implementation_defined
42 beast::detail::buffer_cat_helper<
43 detail::chunk_encode_delim,
45 boost::asio::const_buffers_1>
47 chunk_encode(bool fin, ConstBufferSequence const& buffers)
49 using boost::asio::buffer_size;
51 detail::chunk_encode_delim{buffer_size(buffers)},
53 fin ? boost::asio::const_buffers_1{"\r\n0\r\n\r\n", 7}
54 : boost::asio::const_buffers_1{"\r\n", 2});
57 /** Returns a chunked encoding final chunk.
59 @see <a href=https://tools.ietf.org/html/rfc7230#section-4.1.3>rfc7230 section 4.1.3</a>
63 implementation_defined
65 boost::asio::const_buffers_1
69 return boost::asio::const_buffers_1{"0\r\n\r\n", 5};