1212#ifndef VIX_REQUEST_HPP
1313#define VIX_REQUEST_HPP
1414
15+ #include < functional>
1516#include < memory>
1617#include < stdexcept>
1718#include < string>
2728
2829namespace vix ::http
2930{
31+ #ifndef VIX_HTTP_TRANSPARENT_STRING_TYPES
32+ #define VIX_HTTP_TRANSPARENT_STRING_TYPES
33+ struct TransparentStringHash
34+ {
35+ using is_transparent = void ;
36+
37+ std::size_t operator ()(std::string_view value) const noexcept
38+ {
39+ return std::hash<std::string_view>{}(value);
40+ }
41+
42+ std::size_t operator ()(const std::string &value) const noexcept
43+ {
44+ return std::hash<std::string_view>{}(value);
45+ }
46+
47+ std::size_t operator ()(const char *value) const noexcept
48+ {
49+ return std::hash<std::string_view>{}(value ? std::string_view{value} : std::string_view{});
50+ }
51+ };
52+
53+ struct TransparentStringEqual
54+ {
55+ using is_transparent = void ;
56+
57+ bool operator ()(std::string_view a, std::string_view b) const noexcept
58+ {
59+ return a == b;
60+ }
61+ };
62+ #endif
63+
3064 /* *
3165 * @brief Lightweight native HTTP request object for Vix.
3266 *
@@ -43,7 +77,7 @@ namespace vix::http
4377 using QueryMap = std::unordered_map<std::string, std::string>;
4478
4579 /* * @brief Map of HTTP headers. */
46- using HeaderMap = std::unordered_map<std::string, std::string>;
80+ using HeaderMap = std::unordered_map<std::string, std::string, TransparentStringHash, TransparentStringEqual >;
4781
4882 /* * @brief Shared pointer type for request-scoped state storage. */
4983 using StatePtr = std::shared_ptr<vix::http::RequestState>;
@@ -229,14 +263,14 @@ namespace vix::http
229263 */
230264 std::string header (std::string_view name) const
231265 {
232- auto it = headers_.find (std::string ( name) );
266+ auto it = headers_.find (name);
233267 return it == headers_.end () ? std::string{} : it->second ;
234268 }
235269
236270 /* * @brief Return true if a header exists. */
237271 bool has_header (std::string_view name) const
238272 {
239- return headers_.find (std::string ( name) ) != headers_.end ();
273+ return headers_.find (name) != headers_.end ();
240274 }
241275
242276 /* * @brief Set or replace one header. */
@@ -248,7 +282,11 @@ namespace vix::http
248282 /* * @brief Remove a header if present. */
249283 void remove_header (std::string_view name)
250284 {
251- headers_.erase (std::string (name));
285+ const auto it = headers_.find (name);
286+ if (it != headers_.end ())
287+ {
288+ headers_.erase (it);
289+ }
252290 }
253291
254292 /* * @brief Parse and return the body as JSON, computed lazily. */
0 commit comments