refactor(HttpHeaders): add logging for header operations and clean up includes
This commit is contained in:
parent
feeadb0a21
commit
571625bbbf
@ -65,7 +65,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Simple post-create setup
|
// 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
|
// 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') &"
|
// "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') &"
|
||||||
|
|||||||
@ -1,16 +1,15 @@
|
|||||||
#include "webserv/log/Log.hpp"
|
|
||||||
|
|
||||||
#include <webserv/config/utils.hpp> // for trim
|
#include <webserv/config/utils.hpp> // for trim
|
||||||
#include <webserv/http/HttpConstants.hpp> // for CRLF
|
#include <webserv/http/HttpConstants.hpp> // for CRLF
|
||||||
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
#include <webserv/http/HttpHeaders.hpp> // for HttpHeaders
|
||||||
|
#include <webserv/log/Log.hpp>
|
||||||
|
|
||||||
#include <algorithm> // for __transform_fn, transform
|
#include <algorithm> // for __transform_fn, transform
|
||||||
#include <utility> // for pair
|
|
||||||
|
|
||||||
#include <cctype> // for tolower
|
#include <cctype> // for tolower
|
||||||
|
#include <utility> // for pair
|
||||||
|
|
||||||
std::optional<size_t> HttpHeaders::getContentLength() const
|
std::optional<size_t> HttpHeaders::getContentLength() const
|
||||||
{
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
const auto &value = this->get("Content-Length");
|
const auto &value = this->get("Content-Length");
|
||||||
if (value.empty())
|
if (value.empty())
|
||||||
{
|
{
|
||||||
@ -21,6 +20,7 @@ std::optional<size_t> HttpHeaders::getContentLength() const
|
|||||||
|
|
||||||
std::optional<std::string> HttpHeaders::getContentType() const
|
std::optional<std::string> HttpHeaders::getContentType() const
|
||||||
{
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
const auto &value = this->get("Content-Type");
|
const auto &value = this->get("Content-Type");
|
||||||
if (value.empty())
|
if (value.empty())
|
||||||
{
|
{
|
||||||
@ -31,6 +31,7 @@ std::optional<std::string> HttpHeaders::getContentType() const
|
|||||||
|
|
||||||
std::optional<std::string> HttpHeaders::getHost() const
|
std::optional<std::string> HttpHeaders::getHost() const
|
||||||
{
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
const auto &value = this->get("Host");
|
const auto &value = this->get("Host");
|
||||||
if (value.empty())
|
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)
|
void HttpHeaders::add(const std::string &name, const std::string &value) // NOLINT(bugprone-easily-swappable-parameters)
|
||||||
{
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
std::string lower = name;
|
std::string lower = name;
|
||||||
std::ranges::transform(lower, lower.begin(), ::tolower);
|
std::ranges::transform(lower, lower.begin(), ::tolower);
|
||||||
headers_[lower] = value;
|
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)
|
void HttpHeaders::remove(const std::string &name)
|
||||||
{
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
headers_.erase(name);
|
headers_.erase(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &HttpHeaders::get(const std::string &name) const
|
const std::string &HttpHeaders::get(const std::string &name) const
|
||||||
{
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
std::string lower = name;
|
std::string lower = name;
|
||||||
std::ranges::transform(lower, lower.begin(), ::tolower);
|
std::ranges::transform(lower, lower.begin(), ::tolower);
|
||||||
auto it = headers_.find(lower);
|
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
|
bool HttpHeaders::has(const std::string &name) const
|
||||||
{
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
std::string lower = name;
|
std::string lower = name;
|
||||||
std::ranges::transform(lower, lower.begin(), ::tolower);
|
std::ranges::transform(lower, lower.begin(), ::tolower);
|
||||||
return headers_.contains(lower);
|
return headers_.contains(lower);
|
||||||
@ -74,6 +78,7 @@ bool HttpHeaders::has(const std::string &name) const
|
|||||||
|
|
||||||
void HttpHeaders::parse(const std::string &rawHeaders)
|
void HttpHeaders::parse(const std::string &rawHeaders)
|
||||||
{
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
size_t start = 0;
|
size_t start = 0;
|
||||||
size_t end = rawHeaders.find(Http::Protocol::CRLF);
|
size_t end = rawHeaders.find(Http::Protocol::CRLF);
|
||||||
|
|
||||||
@ -96,6 +101,7 @@ void HttpHeaders::parse(const std::string &rawHeaders)
|
|||||||
|
|
||||||
std::string HttpHeaders::toString() const
|
std::string HttpHeaders::toString() const
|
||||||
{
|
{
|
||||||
|
Log::trace(LOCATION);
|
||||||
std::string result;
|
std::string result;
|
||||||
for (const auto &pair : headers_)
|
for (const auto &pair : headers_)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
#include <webserv/http/HttpRequest.hpp>
|
#include <webserv/http/HttpRequest.hpp>
|
||||||
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
#include <webserv/log/Log.hpp> // for Log, LOCATION
|
||||||
|
|
||||||
#include <exception> // for exception
|
|
||||||
#include <optional> // for optional, operator>
|
#include <optional> // for optional, operator>
|
||||||
#include <sstream> // for basic_stringstream, basic_istream, stringstream
|
#include <sstream> // for basic_stringstream, basic_istream, stringstream
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user