123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737 |
- #ifndef BOOST_BEAST_HTTP_CHUNK_ENCODE_HPP
- #define BOOST_BEAST_HTTP_CHUNK_ENCODE_HPP
- #include <boost/beast/core/detail/config.hpp>
- #include <boost/beast/core/buffers_cat.hpp>
- #include <boost/beast/core/string.hpp>
- #include <boost/beast/http/type_traits.hpp>
- #include <boost/beast/http/detail/chunk_encode.hpp>
- #include <boost/asio/buffer.hpp>
- #include <memory>
- #include <type_traits>
- namespace boost {
- namespace beast {
- namespace http {
- struct chunk_crlf
- {
-
- chunk_crlf() = default;
-
-
- #if BOOST_BEAST_DOXYGEN
- using value_type = __implementation_defined__;
- #else
- using value_type = net::const_buffer;
- #endif
-
- using const_iterator = value_type const*;
-
- chunk_crlf(chunk_crlf const&) = default;
-
- const_iterator
- begin() const
- {
- static net::const_buffer const cb{"\r\n", 2};
- return &cb;
- }
-
- const_iterator
- end() const
- {
- return begin() + 1;
- }
- };
- class chunk_header
- {
- using view_type = buffers_cat_view<
- detail::chunk_size,
- net::const_buffer,
- chunk_crlf>;
- std::shared_ptr<
- detail::chunk_extensions> exts_;
- view_type view_;
- public:
-
- explicit
- chunk_header(std::size_t size);
-
- chunk_header(
- std::size_t size,
- string_view extensions);
-
- template<class ChunkExtensions
- #if ! BOOST_BEAST_DOXYGEN
- , class = typename std::enable_if<
- detail::is_chunk_extensions<
- ChunkExtensions>::value>::type
- #endif
- >
- chunk_header(
- std::size_t size,
- ChunkExtensions&& extensions);
-
- template<class ChunkExtensions, class Allocator
- #if ! BOOST_BEAST_DOXYGEN
- , class = typename std::enable_if<
- detail::is_chunk_extensions<
- ChunkExtensions>::value>::type
- #endif
- >
- chunk_header(
- std::size_t size,
- ChunkExtensions&& extensions,
- Allocator const& allocator);
-
-
- #if BOOST_BEAST_DOXYGEN
- using value_type = __implementation_defined__;
- #else
- using value_type = typename view_type::value_type;
- #endif
-
- #if BOOST_BEAST_DOXYGEN
- using const_iterator = __implementation_defined__;
- #else
- using const_iterator = typename view_type::const_iterator;
- #endif
-
- chunk_header(chunk_header const&) = default;
-
- const_iterator
- begin() const
- {
- return view_.begin();
- }
-
- const_iterator
- end() const
- {
- return view_.end();
- }
- };
- template<class ConstBufferSequence>
- class chunk_body
- {
- using view_type = buffers_cat_view<
- detail::chunk_size,
- net::const_buffer,
- chunk_crlf,
- ConstBufferSequence,
- chunk_crlf>;
- std::shared_ptr<
- detail::chunk_extensions> exts_;
- view_type view_;
- public:
-
- explicit
- chunk_body(
- ConstBufferSequence const& buffers);
-
- chunk_body(
- ConstBufferSequence const& buffers,
- string_view extensions);
-
- template<class ChunkExtensions
- #if ! BOOST_BEAST_DOXYGEN
- , class = typename std::enable_if<
- ! std::is_convertible<typename std::decay<
- ChunkExtensions>::type, string_view>::value>::type
- #endif
- >
- chunk_body(
- ConstBufferSequence const& buffers,
- ChunkExtensions&& extensions);
-
- template<class ChunkExtensions, class Allocator
- #if ! BOOST_BEAST_DOXYGEN
- , class = typename std::enable_if<
- ! std::is_convertible<typename std::decay<
- ChunkExtensions>::type, string_view>::value>::type
- #endif
- >
- chunk_body(
- ConstBufferSequence const& buffers,
- ChunkExtensions&& extensions,
- Allocator const& allocator);
-
-
- #if BOOST_BEAST_DOXYGEN
- using value_type = __implementation_defined__;
- #else
- using value_type = typename view_type::value_type;
- #endif
-
- #if BOOST_BEAST_DOXYGEN
- using const_iterator = __implementation_defined__;
- #else
- using const_iterator = typename view_type::const_iterator;
- #endif
-
- const_iterator
- begin() const
- {
- return view_.begin();
- }
-
- const_iterator
- end() const
- {
- return view_.end();
- }
- };
- template<class Trailer = chunk_crlf>
- class chunk_last
- {
- static_assert(
- is_fields<Trailer>::value ||
- net::is_const_buffer_sequence<Trailer>::value,
- "Trailer requirements not met");
- using buffers_type = typename
- detail::buffers_or_fields<Trailer>::type;
- using view_type =
- buffers_cat_view<
- detail::chunk_size0,
- buffers_type>;
- template<class Allocator>
- buffers_type
- prepare(Trailer const& trailer, Allocator const& alloc);
- buffers_type
- prepare(Trailer const& trailer, std::true_type);
- buffers_type
- prepare(Trailer const& trailer, std::false_type);
- std::shared_ptr<void> sp_;
- view_type view_;
- public:
-
- chunk_last();
-
- explicit
- chunk_last(Trailer const& trailer);
-
- #if BOOST_BEAST_DOXYGEN
- template<class Allocator>
- chunk_last(Trailer const& trailer, Allocator const& allocator);
- #else
- template<class DeducedTrailer, class Allocator,
- class = typename std::enable_if<
- is_fields<DeducedTrailer>::value>::type>
- chunk_last(
- DeducedTrailer const& trailer, Allocator const& allocator);
- #endif
-
-
- chunk_last(chunk_last const&) = default;
-
- #if BOOST_BEAST_DOXYGEN
- using value_type = __implementation_defined__;
- #else
- using value_type =
- typename view_type::value_type;
- #endif
-
- #if BOOST_BEAST_DOXYGEN
- using const_iterator = __implementation_defined__;
- #else
- using const_iterator =
- typename view_type::const_iterator;
- #endif
-
- const_iterator
- begin() const
- {
- return view_.begin();
- }
-
- const_iterator
- end() const
- {
- return view_.end();
- }
- };
- template<class Allocator>
- class basic_chunk_extensions
- {
- std::basic_string<char,
- std::char_traits<char>, Allocator> s_;
- std::basic_string<char,
- std::char_traits<char>, Allocator> range_;
- template<class FwdIt>
- FwdIt
- do_parse(FwdIt it, FwdIt last, error_code& ec);
- void
- do_insert(string_view name, string_view value);
- public:
-
- using value_type = std::pair<string_view, string_view>;
- class const_iterator;
-
- basic_chunk_extensions() = default;
-
- basic_chunk_extensions(basic_chunk_extensions&&) = default;
-
- basic_chunk_extensions(basic_chunk_extensions const&) = default;
-
- explicit
- basic_chunk_extensions(Allocator const& allocator)
- : s_(allocator)
- {
- }
-
- void
- clear()
- {
- s_.clear();
- }
-
- void
- parse(string_view s, error_code& ec);
-
- void
- insert(string_view name);
-
- void
- insert(string_view name, string_view value);
-
- string_view
- str() const
- {
- return s_;
- }
- const_iterator
- begin() const;
- const_iterator
- end() const;
- };
- using chunk_extensions =
- basic_chunk_extensions<std::allocator<char>>;
- template<class ConstBufferSequence, class... Args>
- auto
- make_chunk(
- ConstBufferSequence const& buffers,
- Args&&... args) ->
- chunk_body<ConstBufferSequence>
- {
- return chunk_body<ConstBufferSequence>(
- buffers, std::forward<Args>(args)...);
- }
- inline
- chunk_last<chunk_crlf>
- make_chunk_last()
- {
- return chunk_last<chunk_crlf>{};
- }
- template<class Trailer, class... Args>
- chunk_last<Trailer>
- make_chunk_last(
- Trailer const& trailer,
- Args&&... args)
- {
- return chunk_last<Trailer>{
- trailer, std::forward<Args>(args)...};
- }
- }
- }
- }
- #include <boost/beast/http/impl/chunk_encode.hpp>
- #endif
|