2017-07-20 08:01:46 -07:00
|
|
|
//
|
2017-02-06 20:07:03 -05:00
|
|
|
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-07-20 08:01:46 -07:00
|
|
|
//
|
|
|
|
|
// 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-04-27 17:38:50 -07:00
|
|
|
#ifndef BEAST_HTTP_IMPL_FIELDS_IPP
|
|
|
|
|
#define BEAST_HTTP_IMPL_FIELDS_IPP
|
2017-07-20 08:01:46 -07:00
|
|
|
|
2016-05-24 06:17:04 -04:00
|
|
|
#include <beast/http/detail/rfc7230.hpp>
|
2016-07-04 13:57:59 -04:00
|
|
|
#include <algorithm>
|
2016-05-24 06:17:04 -04:00
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
namespace beast {
|
|
|
|
|
namespace http {
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
void
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
2017-07-20 08:01:46 -07:00
|
|
|
delete_all()
|
|
|
|
|
{
|
|
|
|
|
for(auto it = list_.begin(); it != list_.end();)
|
|
|
|
|
{
|
|
|
|
|
auto& e = *it++;
|
2016-05-04 14:22:58 -04:00
|
|
|
alloc_traits::destroy(this->member(), &e);
|
2017-07-20 08:01:46 -07:00
|
|
|
alloc_traits::deallocate(
|
|
|
|
|
this->member(), &e, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
inline
|
|
|
|
|
void
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
move_assign(basic_fields& other, std::false_type)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
if(this->member() != other.member())
|
|
|
|
|
{
|
|
|
|
|
copy_from(other);
|
|
|
|
|
other.clear();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
set_ = std::move(other.set_);
|
|
|
|
|
list_ = std::move(other.list_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
inline
|
|
|
|
|
void
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
move_assign(basic_fields& other, std::true_type)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
this->member() = std::move(other.member());
|
|
|
|
|
set_ = std::move(other.set_);
|
|
|
|
|
list_ = std::move(other.list_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
inline
|
|
|
|
|
void
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
copy_assign(basic_fields const& other, std::false_type)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
copy_from(other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
inline
|
|
|
|
|
void
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
copy_assign(basic_fields const& other, std::true_type)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
this->member() = other.member();
|
|
|
|
|
copy_from(other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
~basic_fields()
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
delete_all();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
basic_fields(Allocator const& alloc)
|
2017-07-20 08:01:46 -07:00
|
|
|
: beast::detail::empty_base_optimization<
|
|
|
|
|
alloc_type>(alloc)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
basic_fields(basic_fields&& other)
|
2017-07-20 08:01:46 -07:00
|
|
|
: beast::detail::empty_base_optimization<alloc_type>(
|
|
|
|
|
std::move(other.member()))
|
2016-11-10 05:34:49 -05:00
|
|
|
, detail::basic_fields_base(
|
2017-07-20 08:01:46 -07:00
|
|
|
std::move(other.set_), std::move(other.list_))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
auto
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
operator=(basic_fields&& other) ->
|
|
|
|
|
basic_fields&
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
if(this == &other)
|
|
|
|
|
return *this;
|
|
|
|
|
clear();
|
|
|
|
|
move_assign(other, std::integral_constant<bool,
|
|
|
|
|
alloc_traits::propagate_on_container_move_assignment::value>{});
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
basic_fields(basic_fields const& other)
|
|
|
|
|
: basic_fields(alloc_traits::
|
2017-07-20 08:01:46 -07:00
|
|
|
select_on_container_copy_construction(other.member()))
|
|
|
|
|
{
|
|
|
|
|
copy_from(other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
auto
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
operator=(basic_fields const& other) ->
|
|
|
|
|
basic_fields&
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
copy_assign(other, std::integral_constant<bool,
|
|
|
|
|
alloc_traits::propagate_on_container_copy_assignment::value>{});
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
template<class OtherAlloc>
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
basic_fields(basic_fields<OtherAlloc> const& other)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
copy_from(other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
template<class OtherAlloc>
|
|
|
|
|
auto
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
|
|
|
|
operator=(basic_fields<OtherAlloc> const& other) ->
|
|
|
|
|
basic_fields&
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
copy_from(other);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 13:57:59 -04:00
|
|
|
template<class Allocator>
|
|
|
|
|
std::size_t
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
2017-05-05 14:45:15 -07:00
|
|
|
count(string_view const& name) const
|
2016-07-04 13:57:59 -04:00
|
|
|
{
|
|
|
|
|
auto const it = set_.find(name, less{});
|
|
|
|
|
if(it == set_.end())
|
|
|
|
|
return 0;
|
|
|
|
|
auto const last = set_.upper_bound(name, less{});
|
|
|
|
|
return static_cast<std::size_t>(std::distance(it, last));
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
template<class Allocator>
|
|
|
|
|
auto
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
2017-05-05 14:45:15 -07:00
|
|
|
find(string_view const& name) const ->
|
2017-07-20 08:01:46 -07:00
|
|
|
iterator
|
|
|
|
|
{
|
|
|
|
|
auto const it = set_.find(name, less{});
|
|
|
|
|
if(it == set_.end())
|
|
|
|
|
return list_.end();
|
|
|
|
|
return list_.iterator_to(*it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
2017-05-05 14:45:15 -07:00
|
|
|
string_view const
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
2017-05-05 14:45:15 -07:00
|
|
|
operator[](string_view const& name) const
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
|
|
|
|
auto const it = find(name);
|
|
|
|
|
if(it == end())
|
2016-07-04 13:57:59 -04:00
|
|
|
return {};
|
2017-07-20 08:01:46 -07:00
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
void
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
2017-07-20 08:01:46 -07:00
|
|
|
clear() noexcept
|
|
|
|
|
{
|
|
|
|
|
delete_all();
|
|
|
|
|
list_.clear();
|
|
|
|
|
set_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
std::size_t
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
2017-05-05 14:45:15 -07:00
|
|
|
erase(string_view const& name)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-07-04 13:57:59 -04:00
|
|
|
auto it = set_.find(name, less{});
|
2017-07-20 08:01:46 -07:00
|
|
|
if(it == set_.end())
|
|
|
|
|
return 0;
|
2016-07-04 13:57:59 -04:00
|
|
|
auto const last = set_.upper_bound(name, less{});
|
|
|
|
|
std::size_t n = 1;
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
auto& e = *it++;
|
|
|
|
|
set_.erase(set_.iterator_to(e));
|
|
|
|
|
list_.erase(list_.iterator_to(e));
|
|
|
|
|
alloc_traits::destroy(this->member(), &e);
|
|
|
|
|
alloc_traits::deallocate(this->member(), &e, 1);
|
|
|
|
|
if(it == last)
|
|
|
|
|
break;
|
|
|
|
|
++n;
|
|
|
|
|
}
|
|
|
|
|
return n;
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
void
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
2017-05-05 14:45:15 -07:00
|
|
|
insert(string_view const& name,
|
|
|
|
|
string_view value)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-05-24 06:17:04 -04:00
|
|
|
value = detail::trim(value);
|
2016-07-04 13:57:59 -04:00
|
|
|
auto const p = alloc_traits::allocate(this->member(), 1);
|
|
|
|
|
alloc_traits::construct(this->member(), p, name, value);
|
|
|
|
|
set_.insert_before(set_.upper_bound(name, less{}), *p);
|
|
|
|
|
list_.push_back(*p);
|
2017-07-20 08:01:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
void
|
2016-11-10 05:34:49 -05:00
|
|
|
basic_fields<Allocator>::
|
2017-05-05 14:45:15 -07:00
|
|
|
replace(string_view const& name,
|
|
|
|
|
string_view value)
|
2017-07-20 08:01:46 -07:00
|
|
|
{
|
2016-05-24 06:17:04 -04:00
|
|
|
value = detail::trim(value);
|
2017-07-20 08:01:46 -07:00
|
|
|
erase(name);
|
|
|
|
|
insert(name, value);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 06:58:40 -07:00
|
|
|
template<class Allocator>
|
|
|
|
|
string_view
|
|
|
|
|
basic_fields<Allocator>::
|
2017-06-04 10:03:36 -07:00
|
|
|
method_string() const
|
2017-05-30 06:58:40 -07:00
|
|
|
{
|
|
|
|
|
return (*this)[":method"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
void
|
|
|
|
|
basic_fields<Allocator>::
|
2017-06-04 10:03:36 -07:00
|
|
|
method_string(string_view s)
|
2017-05-30 06:58:40 -07:00
|
|
|
{
|
2017-06-04 10:03:36 -07:00
|
|
|
if(s.empty())
|
2017-05-30 06:58:40 -07:00
|
|
|
this->erase(":method");
|
|
|
|
|
else
|
|
|
|
|
this->replace(":method", s);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 08:01:46 -07:00
|
|
|
} // http
|
|
|
|
|
} // beast
|
|
|
|
|
|
|
|
|
|
#endif
|