LibHTTP: Make HeaderMap movable and copyable

This commit is contained in:
Ali Mohammad Pur 2024-11-01 23:52:52 +01:00 committed by Ali Mohammad Pur
parent d704b61066
commit 7f72c28e78
Notes: github-actions[bot] 2024-11-20 20:44:35 +00:00

View file

@ -15,6 +15,19 @@ public:
HeaderMap() = default; HeaderMap() = default;
~HeaderMap() = default; ~HeaderMap() = default;
HeaderMap(Vector<Header> headers)
: m_headers(move(headers))
{
for (auto& header : m_headers)
m_map.set(header.name, header.value);
}
HeaderMap(HeaderMap const&) = default;
HeaderMap(HeaderMap&&) = default;
HeaderMap& operator=(HeaderMap const&) = default;
HeaderMap& operator=(HeaderMap&&) = default;
void set(ByteString name, ByteString value) void set(ByteString name, ByteString value)
{ {
m_map.set(name, value); m_map.set(name, value);
@ -56,10 +69,7 @@ template<>
inline ErrorOr<HTTP::HeaderMap> decode(Decoder& decoder) inline ErrorOr<HTTP::HeaderMap> decode(Decoder& decoder)
{ {
auto headers = TRY(decoder.decode<Vector<HTTP::Header>>()); auto headers = TRY(decoder.decode<Vector<HTTP::Header>>());
HTTP::HeaderMap header_map; return HTTP::HeaderMap { move(headers) };
for (auto& header : headers)
header_map.set(move(header.name), move(header.value));
return header_map;
} }
} }