Orbit Framework
An ultra-modern, asynchronous, cross-platform C++ Web Framework.
Loading...
Searching...
No Matches
HttpRequest.hpp
Go to the documentation of this file.
1#pragma once
2#ifdef _WIN32
3#undef DELETE
4#endif
5#include <string>
6#include <string_view>
7#include <unordered_map>
8#include <orbit/http/json.hpp>
11
12namespace http {
13
18
24 std::string uri;
25 std::unordered_map<std::string, std::string> query;
26 std::string http_version;
27 std::unordered_map<std::string_view, std::string_view, utils::CaseInsensitiveHash, utils::CaseInsensitiveEqual> headers;
28 std::string_view body;
29 std::unordered_map<std::string, std::string> params;
30 std::unordered_map<std::string, std::string> cookies;
31 std::string client_ip;
32 std::string session_id; // Set by SessionManager middleware
33 nlohmann::json user; // Populated by JwtAuth middleware
34
35 mutable nlohmann::json json_body; // Cached parsed JSON
36
43 if (!json_body.empty()) return json_body;
44 if (body.empty()) return nlohmann::json::object();
45 json_body = nlohmann::json::parse(body, nullptr, false); // false = no exceptions
46 return json_body;
47 }
48
54 auto ct = headers.find("Content-Type");
55 if (ct != headers.end() && ct->second.starts_with("multipart/form-data")) {
56 return MultipartForm::parse(ct->second, body);
57 }
58 return {};
59 }
60};
61
62} // namespace http
Represents parsed multipart/form-data content.
Definition MultipartForm.hpp:22
static MultipartForm parse(std::string_view content_type_header, std::string_view body)
Parses a multipart/form-data request body.
Definition MultipartForm.cpp:5
a class to store JSON values
Definition json.hpp:19401
bool empty() const noexcept
checks whether the container is empty.
Definition json.hpp:22208
Definition Http2Session.hpp:21
HttpMethod
Represents standard HTTP methods.
Definition HttpRequest.hpp:17
Represents an incoming HTTP request.
Definition HttpRequest.hpp:22
std::string client_ip
Definition HttpRequest.hpp:31
std::unordered_map< std::string, std::string > params
Definition HttpRequest.hpp:29
nlohmann::json json() const
Parses and returns the request body as a JSON object.
Definition HttpRequest.hpp:42
std::string_view body
Definition HttpRequest.hpp:28
std::string uri
Definition HttpRequest.hpp:24
std::string session_id
Definition HttpRequest.hpp:32
MultipartForm form() const
Parses the request body as multipart/form-data.
Definition HttpRequest.hpp:53
nlohmann::json json_body
Definition HttpRequest.hpp:35
std::unordered_map< std::string, std::string > cookies
Definition HttpRequest.hpp:30
std::unordered_map< std::string, std::string > query
Definition HttpRequest.hpp:25
HttpMethod method
Definition HttpRequest.hpp:23
std::string http_version
Definition HttpRequest.hpp:26
std::unordered_map< std::string_view, std::string_view, utils::CaseInsensitiveHash, utils::CaseInsensitiveEqual > headers
Definition HttpRequest.hpp:27
nlohmann::json user
Definition HttpRequest.hpp:33