Files
codam-webserver-team/src/http/Request.cpp
T
2026-09-12 08:29:44 +02:00

45 lines
1.4 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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