#pragma once #include "common.hpp" #include "cookie.hpp" #include #include using std::string_view; using std::string; struct Request { HttpMethod method = HttpMethod::UNKNOWN; string_view path; string_view query; string_view version; string_view body; std::unordered_map headers; std::unordered_map params; // URL parameters std::vector cookies; // Parsed cookies size_t content_length = 0; bool valid = false; string_view get_cookie(string_view name) const { return CookieHelpers::get_cookie(cookies, name); } string session_id() const { return string(get_cookie("session_id")); } string get_param(string_view key) const { auto it = params.find(key); return it != params.end() ? string(it->second) : string{}; } int get_param_int(string_view key) const { auto it = params.find(key); if (it == params.end()) return 0; int result = 0; for (char c : it->second) { if (c >= '0' && c <= '9') { result = result * 10 + (c - '0'); } else { break; } } return result; } };