#pragma once // This header needs to be included before beast headers // because of a bit of a bug. I hope 1.84 solves this //clang-format off #include //clang-format on #include #include #include #include #include #include #include #include namespace base::http { struct Request { using BeastRequest = beast::http::request; Request(BeastRequest& request, burl::url_view url, r3::MatchEntry& me) : req(request), url(url) { BASE_ASSERT(me.get() != nullptr, "Request constructor requires a valid match entry.."); // convert data from r3 into something with brain cells auto& data = me.get()->vars; for(u32 i = 0; i < data.tokens.size; ++i) { auto& siov = data.slugs.entries[i]; auto& eiov = data.tokens.entries[i]; matches[R3IovecString(siov)] = R3IovecString(eiov); } // convert boost.URL params for(auto kv : url.params()) { if(kv.key.empty()) continue; if(kv.has_value) { query[kv.key] = kv.value; } else { query[kv.key] = ""; } } } BeastRequest& Native() { return req; } const auto& Matches() const { return matches; } const std::string& Get(const std::string& key) const { return matches.at(key); } asio::ip::address src; std::unordered_map matches; // Query string parameters std::unordered_map query; private: friend struct Server; BeastRequest req; burl::url_view url; }; } // namespace base::http