46 [[nodiscard]]
auto get_header(std::string_view name)
const
47 -> std::optional<std::string>
51 if (h.name.size() != name.size()) return false;
52 for (size_t i = 0; i < h.name.size(); ++i) {
53 if (std::tolower(static_cast<unsigned char>(h.name[i])) !=
54 std::tolower(static_cast<unsigned char>(name[i]))) {
70 [[nodiscard]]
auto content_type() const -> std::optional<std::
string>
72 return get_header(
"content-type");
81 auto value = get_header(
"content-length");
86 return static_cast<size_t>(std::stoull(*value));
98 return std::string(body.begin(), body.end());
112 if (method.empty()) {
116 if (method ==
"CONNECT") {
117 return !authority.empty();
120 return !scheme.empty() && !path.empty();
131 static auto from_headers(
const std::vector<http_header>& parsed_headers)
135 for (
const auto& header : parsed_headers) {
136 if (header.name.empty()) {
139 if (header.name[0] ==
':') {
141 if (header.name ==
":method") {
142 request.
method = header.value;
143 }
else if (header.name ==
":path") {
144 request.
path = header.value;
145 }
else if (header.name ==
":scheme") {
146 request.
scheme = header.value;
147 }
else if (header.name ==
":authority") {
153 request.
headers.push_back(header);
HTTP/2 request data structure.
auto content_type() const -> std::optional< std::string >
Get Content-Type header value.
std::vector< uint8_t > body
Request body from DATA frames.
static auto from_headers(const std::vector< http_header > &parsed_headers) -> http2_request
Create http2_request from parsed headers.
auto get_body_string() const -> std::string
Get request body as UTF-8 string.
std::string path
Request path (:path pseudo-header)
std::string authority
Authority (:authority pseudo-header)
auto is_valid() const -> bool
Check if this is a valid HTTP/2 request.
std::vector< http_header > headers
Regular headers (non-pseudo)
auto content_length() const -> std::optional< size_t >
Get Content-Length header value as size_t.
auto get_header(std::string_view name) const -> std::optional< std::string >
Get header value by name (case-insensitive)
std::string scheme
Scheme (:scheme pseudo-header)
std::string method
HTTP method (:method pseudo-header)