feat(headers): getContentType and getHost

This commit is contained in:
Quinten Mennen 2025-09-24 11:22:21 +02:00
parent e921290d8f
commit e43bf72cd6
2 changed files with 23 additions and 1 deletions

View File

@ -8,7 +8,7 @@
std::optional<size_t> HttpHeaders::getContentLength() const
{
const auto &value = get("Content-Length");
const auto &value = this->get("Content-Length");
if (value.empty())
{
return std::nullopt;
@ -23,6 +23,26 @@ std::optional<size_t> HttpHeaders::getContentLength() const
}
}
std::optional<std::string> HttpHeaders::getContentType() const
{
const auto &value = this->get("Content-Type");
if (value.empty())
{
return std::nullopt;
}
return value;
}
std::optional<std::string> HttpHeaders::getHost() const
{
const auto &value = this->get("Host");
if (value.empty())
{
return std::nullopt;
}
return value;
}
void HttpHeaders::add(const std::string &name, const std::string &value) // NOLINT(bugprone-easily-swappable-parameters)
{

View File

@ -36,6 +36,8 @@ class HttpHeaders
std::string toString() const;
std::optional<size_t> getContentLength() const;
std::optional<std::string> getContentType() const;
std::optional<std::string> getHost() const;
private:
std::unordered_map<std::string, std::string> headers_;