Webserv
Loading...
Searching...
No Matches
Headers.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <map>
4
#include <sstream>
5
#include <string>
6
7
namespace
http
{
8
17
class
Headers
{
18
public
:
19
typedef
std::map<std::string, std::string>
HeaderMap
;
20
typedef
HeaderMap::iterator
iterator
;
21
typedef
HeaderMap::const_iterator
const_iterator
;
22
23
public
:
27
Headers
();
28
34
bool
has
(std::string
const
&key)
const
;
35
42
Headers
&
add
(std::string
const
&key, std::string
const
&value);
43
50
bool
get
(
const
std::string &key, std::string &value)
const
;
51
57
std::string
get
(
const
std::string &key)
const
;
58
59
65
size_t
getContentLength
()
const
;
66
71
bool
isContentChunked
()
const
;
72
77
Headers
&
clear
();
78
84
Headers
&
erase
(std::string
const
&key);
85
91
std::string
toString
()
const
;
92
98
HeaderMap
const
&
getMap
()
const
;
99
100
const_iterator
find
(std::string
const
&key)
const
;
101
const_iterator
begin
()
const
;
102
const_iterator
end
()
const
;
103
104
public
:
113
static
bool
parse
(std::string &,
Headers
&,
bool
strict =
false
);
114
116
static
bool
parse
(std::istringstream &,
Headers
&,
bool
strict =
false
);
117
125
static
size_t
findHeaderEnd
(
const
std::string &buffer,
size_t
&offset);
126
127
private
:
132
static
void
normalizeKey
(std::string &key);
133
138
static
std::string
normalizeKey
(std::string
const
&key);
139
145
HeaderMap
map_
;
146
};
147
148
}
// namespace http
http::Headers::findHeaderEnd
static size_t findHeaderEnd(const std::string &buffer, size_t &offset)
Finds the end of the HTTP header section in a buffer. Compatible with \r \r , , \r ,...
Definition
Headers.cpp:118
http::Headers::parse
static bool parse(std::string &, Headers &, bool strict=false)
Parses a raw string of headers into a provided Headers reference. The string should contain multiple ...
Definition
Headers.cpp:77
http::Headers::get
bool get(const std::string &key, std::string &value) const
C++98-style getter. Retrieves a header value.
Definition
Headers.cpp:27
http::Headers::iterator
HeaderMap::iterator iterator
Definition
Headers.hpp:20
http::Headers::isContentChunked
bool isContentChunked() const
Checks if the 'Transfer-Encoding' header is set to 'chunked'.
Definition
Headers.cpp:82
http::Headers::toString
std::string toString() const
Serializes all headers into a single string. Each header is on its own line, formatted as "Key: Value...
Definition
Headers.cpp:100
http::Headers::find
const_iterator find(std::string const &key) const
Definition
Headers.cpp:114
http::Headers::const_iterator
HeaderMap::const_iterator const_iterator
Definition
Headers.hpp:21
http::Headers::normalizeKey
static void normalizeKey(std::string &key)
Internal: Normalizes a key to lowercase in-place.
Definition
Headers.cpp:10
http::Headers::add
Headers & add(std::string const &key, std::string const &value)
Adds or overwrites a header key-value pair.
Definition
Headers.cpp:20
http::Headers::HeaderMap
std::map< std::string, std::string > HeaderMap
Definition
Headers.hpp:19
http::Headers::erase
Headers & erase(std::string const &key)
Removes a single header by its key.
Definition
Headers.cpp:95
http::Headers::clear
Headers & clear()
Clears all headers from the map.
Definition
Headers.cpp:90
http::Headers::map_
HeaderMap map_
The internal storage for headers, mapping lowercase_key -> Original_Value.
Definition
Headers.hpp:145
http::Headers::getMap
HeaderMap const & getMap() const
Returns a const reference to the internal header map. Useful for iterating over all headers (e....
Definition
Headers.cpp:109
http::Headers::end
const_iterator end() const
Definition
Headers.cpp:112
http::Headers::getContentLength
size_t getContentLength() const
A specialized accessor for the Content-Length header.
Definition
Headers.cpp:41
http::Headers::has
bool has(std::string const &key) const
Checks if a header with the given key exists.
Definition
Headers.cpp:110
http::Headers::Headers
Headers()
Constructs an empty Headers object.
Definition
Headers.cpp:8
http::Headers::begin
const_iterator begin() const
Definition
Headers.cpp:111
http
Definition
IArgument.hpp:5
inc
http
Headers.hpp
Generated by
1.14.0