6#include <boost/beast/http/string_body.hpp>
8#include <unordered_map>
16 template<
typename Body = boost::beast::http::
string_body>
18 public boost::beast::http::request<Body>
20 using msg_t = boost::beast::http::request<Body>;
37 msg_t::method(method_);
38 msg_t::target(target_);
39 msg_t::set(http::field::host, host);
50 using namespace boost::beast::http;
53 msg_t::operator=(std::move(raw));
57 const auto &[begin, end] = msg_t::base().equal_range(field::cookie);
58 for (
auto it = begin; it != end; it++) {
59 const auto &str = it->value();
61 const auto &sep_pos = it->value().find(
'=');
62 if (sep_pos == std::string::npos)
65 std::string key{str.substr(0, sep_pos)};
66 std::string value{str.substr(sep_pos + 1)};
67 m_cookies.insert_or_assign(std::move(key), std::move(value));
128 std::unordered_map<std::string, std::string>
143 return m_cookies.contains(name);
151 cookie(
const std::string_view& name)
const
153 const auto& it = std::find_if(
154 std::cbegin(m_cookies),
155 std::cend(m_cookies),
156 [&name](
const auto& pair) {
157 return pair.first == name;
161 if (it == std::cend(m_cookies))
168 std::uint16_t m_port = 0;
169 std::unordered_map<std::string, std::string> m_cookies;
178 template<
typename Body>
183 std::ostringstream ss;
Definition: request.hpp:19
request & operator=(request &&rhs) noexcept=default
request(const request &other)=default
std::uint16_t port() const noexcept
Definition: request.hpp:117
request & operator=(const request &rhs)=default
std::string_view cookie(const std::string_view &name) const
Definition: request.hpp:151
request(request &&other) noexcept=default
request(http::method method_, std::string_view host, const std::uint16_t port, std::string_view target_)
Definition: request.hpp:33
std::unordered_map< std::string, std::string > cookies() const noexcept
Definition: request.hpp:129
bool has_cookie(const std::string &name) const
Definition: request.hpp:141
virtual ~request()=default
request(msg_t &&raw)
Definition: request.hpp:48
boost::beast::http::verb method
Definition: types.hpp:18
Definition: controller.hpp:31
std::string_view to_string(const malloy::http::method method)
Definition: http.hpp:26