From 571625bbbf4708a3f8312371904bcec139628472 Mon Sep 17 00:00:00 2001 From: whaffman Date: Wed, 24 Sep 2025 22:37:44 +0200 Subject: [PATCH] refactor(HttpHeaders): add logging for header operations and clean up includes --- .devcontainer/devcontainer.json | 2 +- webserv/http/HttpHeaders.cpp | 16 +++++++++++----- webserv/http/HttpRequest.cpp | 7 +++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ee0281e..d62bc0a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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') &" diff --git a/webserv/http/HttpHeaders.cpp b/webserv/http/HttpHeaders.cpp index 1456fcf..6a75d38 100644 --- a/webserv/http/HttpHeaders.cpp +++ b/webserv/http/HttpHeaders.cpp @@ -1,16 +1,15 @@ -#include "webserv/log/Log.hpp" - #include // for trim #include // for CRLF #include // for HttpHeaders +#include #include // for __transform_fn, transform +#include // for tolower #include // for pair -#include // for tolower - std::optional HttpHeaders::getContentLength() const { + Log::trace(LOCATION); const auto &value = this->get("Content-Length"); if (value.empty()) { @@ -21,6 +20,7 @@ std::optional HttpHeaders::getContentLength() const std::optional HttpHeaders::getContentType() const { + Log::trace(LOCATION); const auto &value = this->get("Content-Type"); if (value.empty()) { @@ -31,6 +31,7 @@ std::optional HttpHeaders::getContentType() const std::optional HttpHeaders::getHost() const { + Log::trace(LOCATION); const auto &value = this->get("Host"); if (value.empty()) { @@ -41,7 +42,7 @@ std::optional 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_) { diff --git a/webserv/http/HttpRequest.cpp b/webserv/http/HttpRequest.cpp index 82a0aaa..321d953 100644 --- a/webserv/http/HttpRequest.cpp +++ b/webserv/http/HttpRequest.cpp @@ -4,10 +4,9 @@ #include #include // for Log, LOCATION -#include // for exception -#include // for optional, operator> -#include // for basic_stringstream, basic_istream, stringstream -#include // for vector +#include // for optional, operator> +#include // for basic_stringstream, basic_istream, stringstream +#include // for vector class ServerConfig;