one more parser

This commit is contained in:
2026-09-12 08:29:44 +02:00
parent 751b54db18
commit 72d072bb6c
5 changed files with 287 additions and 4 deletions
+44
View File
@@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Request.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* +#+#+#+#+#+ +#+ */
/* */
/* ************************************************************************** */
#include "http/Request.hpp"
#include <algorithm>
#include <cctype>
namespace webserv {
const char* toString(Method method) noexcept {
switch (method) {
case Method::Get:
return "GET";
case Method::Post:
return "POST";
case Method::Delete:
return "DELETE";
}
return "GET";
}
bool headerNameEquals(std::string_view a, std::string_view b) noexcept {
return std::ranges::equal(a, b, [](unsigned char x, unsigned char y) {
return std::tolower(x) == std::tolower(y);
});
}
std::optional<std::string_view> Request::header(std::string_view name) const noexcept {
for (const auto& [fieldName, value] : headers) {
if (headerNameEquals(fieldName, name)) {
return std::string_view(value);
}
}
return std::nullopt;
}
} // namespace webserv