From 7f72c28e78bdce06d8702f87c938c8014a8ce189 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 1 Nov 2024 23:52:52 +0100 Subject: [PATCH] LibHTTP: Make HeaderMap movable and copyable --- Libraries/LibHTTP/HeaderMap.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Libraries/LibHTTP/HeaderMap.h b/Libraries/LibHTTP/HeaderMap.h index f9b8554faae..5d86f0ed537 100644 --- a/Libraries/LibHTTP/HeaderMap.h +++ b/Libraries/LibHTTP/HeaderMap.h @@ -15,6 +15,19 @@ public: HeaderMap() = default; ~HeaderMap() = default; + HeaderMap(Vector
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) { m_map.set(name, value); @@ -56,10 +69,7 @@ template<> inline ErrorOr decode(Decoder& decoder) { auto headers = TRY(decoder.decode>()); - HTTP::HeaderMap header_map; - for (auto& header : headers) - header_map.set(move(header.name), move(header.value)); - return header_map; + return HTTP::HeaderMap { move(headers) }; } }