6#include <boost/beast/core/string.hpp>
7#include <boost/beast/http/message.hpp>
14 template<
bool isReq,
typename Fields>
17 resource_string(
const boost::beast::http::header<isReq, Fields>& header)
19 const auto target = header.target();
21 const auto pos = target.find_first_of(
"?#");
22 if (pos == std::string::npos)
25 return target.substr(0, pos);
28 template<
bool isReq,
typename Fields>
30 chop_resource(boost::beast::http::header<isReq, Fields>& head, std::string_view resource)
32 head.target(head.target().substr(resource.size()));
35 template<
bool isReq,
typename Fields>
38 has_field(
const boost::beast::http::header<isReq, Fields>& head,
const malloy::http::field check)
40 return head.find(check) != head.end();
59 std::vector<std::string_view>
62 using namespace std::literals;
76 template<
bool isReq,
typename Fields>
78 std::optional<std::string_view>
79 cookie_value(
const boost::beast::http::header<isReq, Fields>& header,
const std::string_view cookie_name)
81 const auto& [begin, end] = header.equal_range(field::cookie);
82 for (
auto it = begin; it != end; it++) {
83 const auto& str = it->value();
85 const auto& sep_pos = it->value().find(
'=');
86 if (sep_pos == std::string::npos)
89 const std::string_view key{ str.substr(0, sep_pos) };
90 const std::string_view value{ str.substr(sep_pos+1) };
92 if (key != cookie_name)
std::optional< std::string_view > cookie_value(const boost::beast::http::header< isReq, Fields > &header, const std::string_view cookie_name)
Definition: utils.hpp:79
boost::beast::http::field field
Definition: types.hpp:28
std::vector< std::string_view > split_header_value(std::string_view field_value)
Definition: utils.hpp:60
std::vector< std::string_view > split(std::string_view str, std::string_view delimiter)
Definition: utils.hpp:88