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));
154 std::unordered_map<std::string, std::string>
169 return m_cookies.contains(name);
177 cookie(
const std::string_view& name)
const
179 const auto& it = std::find_if(
180 std::cbegin(m_cookies),
181 std::cend(m_cookies),
182 [&name](
const auto& pair) {
183 return pair.first == name;
187 if (it == std::cend(m_cookies))
194 bool m_use_tls =
false;
195 std::uint16_t m_port = 0;
196 std::unordered_map<std::string, std::string> m_cookies;
205 template<
typename Body>
210 std::ostringstream ss;
Definition: request.hpp:19
request & operator=(request &&rhs) noexcept=default
request(const request &other)=default
constexpr bool use_tls() const noexcept
Definition: request.hpp:130
constexpr void use_tls(const bool enabled) noexcept
Definition: request.hpp:117
constexpr std::uint16_t port() const noexcept
Definition: request.hpp:143
request & operator=(const request &rhs)=default
std::string_view cookie(const std::string_view &name) const
Definition: request.hpp:177
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:155
bool has_cookie(const std::string &name) const
Definition: request.hpp:167
virtual ~request()=default
request(msg_t &&raw)
Definition: request.hpp:48
boost::beast::http::verb method
Definition: types.hpp:18
Definition: controller.hpp:32
std::string_view to_string(const malloy::http::method method)
Definition: http.hpp:26