refactor(HttpHeaders): add logging for header operations and clean up includes

This commit is contained in:
whaffman 2025-09-24 22:37:44 +02:00
parent feeadb0a21
commit 571625bbbf
3 changed files with 15 additions and 10 deletions

View File

@ -65,7 +65,7 @@
},
// Simple post-create setup
"postCreateCommand": "echo 'Dev container ready! Use GitHub CLI (gh auth login) or configure Git with HTTPS for GitHub access.'",
"postCreateCommand": "echo 'Dev container ready! Use GitHub CLI (gh auth login) or configure Git with HTTPS for GitHub access.'"
// Clean build directory and optionally build every time VS Code attaches to container
// "postAttachCommand": "rm -rf /workspaces/webserv/build && echo 'Cleaned build directory for container environment' && (cd /workspaces/webserv && timeout 60 make debug && echo 'Initial build completed successfully' || echo 'Initial build failed or timed out - you can build manually with: make debug') &"

View File

@ -1,16 +1,15 @@
#include "webserv/log/Log.hpp"
#include <webserv/config/utils.hpp> // for trim
#include <webserv/http/HttpConstants.hpp> // for CRLF
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
#include <webserv/log/Log.hpp>
#include <algorithm> // for __transform_fn, transform
#include <cctype> // for tolower
#include <utility> // for pair
#include <cctype> // for tolower
std::optional<size_t> HttpHeaders::getContentLength() const
{
Log::trace(LOCATION);
const auto &value = this->get("Content-Length");
if (value.empty())
{
@ -21,6 +20,7 @@ std::optional<size_t> HttpHeaders::getContentLength() const
std::optional<std::string> HttpHeaders::getContentType() const
{
Log::trace(LOCATION);
const auto &value = this->get("Content-Type");
if (value.empty())
{
@ -31,6 +31,7 @@ std::optional<std::string> HttpHeaders::getContentType() const
std::optional<std::string> HttpHeaders::getHost() const
{
Log::trace(LOCATION);
const auto &value = this->get("Host");
if (value.empty())
{
@ -41,7 +42,7 @@ std::optional<std::string> HttpHeaders::getHost() const
void HttpHeaders::add(const std::string &name, const std::string &value) // NOLINT(bugprone-easily-swappable-parameters)
{
Log::trace(LOCATION);
std::string lower = name;
std::ranges::transform(lower, lower.begin(), ::tolower);
headers_[lower] = value;
@ -49,11 +50,13 @@ void HttpHeaders::add(const std::string &name, const std::string &value) // NOLI
void HttpHeaders::remove(const std::string &name)
{
Log::trace(LOCATION);
headers_.erase(name);
}
const std::string &HttpHeaders::get(const std::string &name) const
{
Log::trace(LOCATION);
std::string lower = name;
std::ranges::transform(lower, lower.begin(), ::tolower);
auto it = headers_.find(lower);
@ -67,6 +70,7 @@ const std::string &HttpHeaders::get(const std::string &name) const
bool HttpHeaders::has(const std::string &name) const
{
Log::trace(LOCATION);
std::string lower = name;
std::ranges::transform(lower, lower.begin(), ::tolower);
return headers_.contains(lower);
@ -74,6 +78,7 @@ bool HttpHeaders::has(const std::string &name) const
void HttpHeaders::parse(const std::string &rawHeaders)
{
Log::trace(LOCATION);
size_t start = 0;
size_t end = rawHeaders.find(Http::Protocol::CRLF);
@ -96,6 +101,7 @@ void HttpHeaders::parse(const std::string &rawHeaders)
std::string HttpHeaders::toString() const
{
Log::trace(LOCATION);
std::string result;
for (const auto &pair : headers_)
{

View File

@ -4,10 +4,9 @@
#include <webserv/http/HttpRequest.hpp>
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <exception> // for exception
#include <optional> // for optional, operator>
#include <sstream> // for basic_stringstream, basic_istream, stringstream
#include <vector> // for vector
#include <optional> // for optional, operator>
#include <sstream> // for basic_stringstream, basic_istream, stringstream
#include <vector> // for vector
class ServerConfig;