123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807 |
- #ifndef BOOST_BEAST_HTTP_FIELDS_HPP
- #define BOOST_BEAST_HTTP_FIELDS_HPP
- #include <boost/beast/core/detail/config.hpp>
- #include <boost/beast/core/string.hpp>
- #include <boost/beast/core/detail/allocator.hpp>
- #include <boost/beast/http/field.hpp>
- #include <boost/asio/buffer.hpp>
- #include <boost/core/empty_value.hpp>
- #include <boost/intrusive/list.hpp>
- #include <boost/intrusive/set.hpp>
- #include <boost/optional.hpp>
- #include <algorithm>
- #include <cctype>
- #include <cstring>
- #include <memory>
- #include <string>
- #include <type_traits>
- #include <utility>
- namespace boost {
- namespace beast {
- namespace http {
- template<class Allocator>
- class basic_fields
- #if ! BOOST_BEAST_DOXYGEN
- : private boost::empty_value<Allocator>
- #endif
- {
-
- static_assert(std::is_pointer<typename
- std::allocator_traits<Allocator>::pointer>::value,
- "Allocator must use regular pointers");
- #ifndef BOOST_BEAST_DOXYGEN
- friend class fields_test;
- #endif
- struct element;
- using off_t = std::uint16_t;
- public:
-
- using allocator_type = Allocator;
-
- class value_type
- {
- #ifndef BOOST_BEAST_DOXYGEN
- friend class basic_fields;
- #endif
- off_t off_;
- off_t len_;
- field f_;
- char*
- data() const;
- net::const_buffer
- buffer() const;
- protected:
- value_type(field name,
- string_view sname, string_view value);
- public:
-
- value_type(value_type const&) = delete;
-
- value_type& operator=(value_type const&) = delete;
-
- field
- name() const;
-
- string_view const
- name_string() const;
-
- string_view const
- value() const;
- };
-
- #if BOOST_BEAST_DOXYGEN
- using key_compare = __implementation_defined__;
- #else
- struct key_compare : beast::iless
- #endif
- {
-
- bool
- operator()(
- string_view lhs,
- value_type const& rhs) const noexcept
- {
- if(lhs.size() < rhs.name_string().size())
- return true;
- if(lhs.size() > rhs.name_string().size())
- return false;
- return iless::operator()(lhs, rhs.name_string());
- }
-
- bool
- operator()(
- value_type const& lhs,
- string_view rhs) const noexcept
- {
- if(lhs.name_string().size() < rhs.size())
- return true;
- if(lhs.name_string().size() > rhs.size())
- return false;
- return iless::operator()(lhs.name_string(), rhs);
- }
-
- bool
- operator()(
- value_type const& lhs,
- value_type const& rhs) const noexcept
- {
- if(lhs.name_string().size() < rhs.name_string().size())
- return true;
- if(lhs.name_string().size() > rhs.name_string().size())
- return false;
- return iless::operator()(lhs.name_string(), rhs.name_string());
- }
- };
-
- #if BOOST_BEAST_DOXYGEN
- using writer = __implementation_defined__;
- #else
- class writer;
- #endif
- private:
- struct element
- : public boost::intrusive::list_base_hook<
- boost::intrusive::link_mode<
- boost::intrusive::normal_link>>
- , public boost::intrusive::set_base_hook<
- boost::intrusive::link_mode<
- boost::intrusive::normal_link>>
- , public value_type
- {
- element(field name,
- string_view sname, string_view value);
- };
- using list_t = typename boost::intrusive::make_list<
- element,
- boost::intrusive::constant_time_size<false>
- >::type;
- using set_t = typename boost::intrusive::make_multiset<
- element,
- boost::intrusive::constant_time_size<false>,
- boost::intrusive::compare<key_compare>
- >::type;
- using align_type = typename
- boost::type_with_alignment<alignof(element)>::type;
- using rebind_type = typename
- beast::detail::allocator_traits<Allocator>::
- template rebind_alloc<align_type>;
- using alloc_traits =
- beast::detail::allocator_traits<rebind_type>;
- using pocma = typename
- alloc_traits::propagate_on_container_move_assignment;
- using pocca = typename
- alloc_traits::propagate_on_container_copy_assignment;
- using pocs = typename
- alloc_traits::propagate_on_container_swap;
- using size_type = typename
- beast::detail::allocator_traits<Allocator>::size_type;
- public:
-
- ~basic_fields();
-
- basic_fields() = default;
-
- explicit
- basic_fields(Allocator const& alloc) noexcept;
-
- basic_fields(basic_fields&&) noexcept;
-
- basic_fields(basic_fields&&, Allocator const& alloc);
-
- basic_fields(basic_fields const&);
-
- basic_fields(basic_fields const&, Allocator const& alloc);
-
- template<class OtherAlloc>
- basic_fields(basic_fields<OtherAlloc> const&);
-
- template<class OtherAlloc>
- basic_fields(basic_fields<OtherAlloc> const&,
- Allocator const& alloc);
-
- basic_fields& operator=(basic_fields&&) noexcept(
- pocma::value && std::is_nothrow_move_assignable<Allocator>::value);
-
- basic_fields& operator=(basic_fields const&);
-
- template<class OtherAlloc>
- basic_fields& operator=(basic_fields<OtherAlloc> const&);
- public:
-
- #if BOOST_BEAST_DOXYGEN
- using const_iterator = __implementation_defined__;
- #else
- using const_iterator = typename list_t::const_iterator;
- #endif
-
- using iterator = const_iterator;
-
- allocator_type
- get_allocator() const
- {
- return this->get();
- }
-
-
-
-
-
-
- string_view const
- at(field name) const;
-
- string_view const
- at(string_view name) const;
-
- string_view const
- operator[](field name) const;
-
- string_view const
- operator[](string_view name) const;
-
-
-
-
-
-
- const_iterator
- begin() const
- {
- return list_.cbegin();
- }
-
- const_iterator
- end() const
- {
- return list_.cend();
- }
-
- const_iterator
- cbegin() const
- {
- return list_.cbegin();
- }
-
- const_iterator
- cend() const
- {
- return list_.cend();
- }
-
-
-
-
-
- private:
-
-
- bool
- empty() const
- {
- return list_.empty();
- }
- public:
-
-
-
-
-
-
- void
- clear();
-
- void
- insert(field name, string_view const& value);
-
- void
- insert(field, std::nullptr_t) = delete;
-
- void
- insert(string_view name, string_view const& value);
-
- void
- insert(string_view, std::nullptr_t) = delete;
-
- void
- insert(field name, string_view name_string,
- string_view const& value);
- void
- insert(field, string_view, std::nullptr_t) = delete;
-
- void
- set(field name, string_view const& value);
- void
- set(field, std::nullptr_t) = delete;
-
- void
- set(string_view name, string_view const& value);
- void
- set(string_view, std::nullptr_t) = delete;
-
- const_iterator
- erase(const_iterator pos);
-
- std::size_t
- erase(field name);
-
- std::size_t
- erase(string_view name);
-
-
- void
- swap(basic_fields& other);
-
- template<class Alloc>
- friend
- void
- swap(basic_fields<Alloc>& lhs, basic_fields<Alloc>& rhs);
-
-
-
-
-
-
- std::size_t
- count(field name) const;
-
- std::size_t
- count(string_view name) const;
-
- const_iterator
- find(field name) const;
-
- const_iterator
- find(string_view name) const;
-
- std::pair<const_iterator, const_iterator>
- equal_range(field name) const;
-
- std::pair<const_iterator, const_iterator>
- equal_range(string_view name) const;
-
-
-
-
-
-
- key_compare
- key_comp() const
- {
- return key_compare{};
- }
- protected:
-
- string_view
- get_method_impl() const;
-
- string_view
- get_target_impl() const;
-
- string_view
- get_reason_impl() const;
-
- bool
- get_chunked_impl() const;
-
- bool
- get_keep_alive_impl(unsigned version) const;
-
- bool
- has_content_length_impl() const;
-
- void
- set_method_impl(string_view s);
-
- void
- set_target_impl(string_view s);
-
- void
- set_reason_impl(string_view s);
-
- void
- set_chunked_impl(bool value);
-
- void
- set_content_length_impl(
- boost::optional<std::uint64_t> const& value);
-
- void
- set_keep_alive_impl(
- unsigned version, bool keep_alive);
- private:
- template<class OtherAlloc>
- friend class basic_fields;
- element&
- new_element(field name,
- string_view sname, string_view value);
- void
- delete_element(element& e);
- void
- set_element(element& e);
- void
- realloc_string(string_view& dest, string_view s);
- void
- realloc_target(
- string_view& dest, string_view s);
- template<class OtherAlloc>
- void
- copy_all(basic_fields<OtherAlloc> const&);
- void
- clear_all();
- void
- delete_list();
- void
- move_assign(basic_fields&, std::true_type);
- void
- move_assign(basic_fields&, std::false_type);
- void
- copy_assign(basic_fields const&, std::true_type);
- void
- copy_assign(basic_fields const&, std::false_type);
- void
- swap(basic_fields& other, std::true_type);
- void
- swap(basic_fields& other, std::false_type);
- set_t set_;
- list_t list_;
- string_view method_;
- string_view target_or_reason_;
- };
- using fields = basic_fields<std::allocator<char>>;
- }
- }
- }
- #include <boost/beast/http/impl/fields.hpp>
- #endif
|