LibHTTP+RequestServer: Use HTTP::HeaderMap for request headers

No longer just for response headers! The same type is obviously useful
and ergonomic when making requests as well.
This commit is contained in:
Andreas Kling 2024-06-09 13:46:04 +02:00 committed by Andreas Kling
commit 260c5c50ad
Notes: sideshowbarker 2024-07-16 22:58:46 +09:00
20 changed files with 41 additions and 54 deletions

View file

@ -12,6 +12,7 @@
#include <AK/Optional.h>
#include <AK/Vector.h>
#include <LibCore/Forward.h>
#include <LibHTTP/HeaderMap.h>
#include <LibURL/URL.h>
namespace HTTP {
@ -55,11 +56,6 @@ public:
PUT,
};
struct Header {
ByteString name;
ByteString value;
};
struct BasicAuthenticationCredentials {
ByteString username;
ByteString password;
@ -69,7 +65,7 @@ public:
~HttpRequest() = default;
ByteString const& resource() const { return m_resource; }
Vector<Header> const& headers() const { return m_headers; }
HeaderMap const& headers() const { return m_headers; }
URL::URL const& url() const { return m_url; }
void set_url(URL::URL const& url) { m_url = url; }
@ -83,7 +79,7 @@ public:
StringView method_name() const;
ErrorOr<ByteBuffer> to_raw_request() const;
void set_headers(HashMap<ByteString, ByteString> const&);
void set_headers(HeaderMap);
static ErrorOr<HttpRequest, HttpRequest::ParseError> from_raw_request(ReadonlyBytes);
static Optional<Header> get_http_basic_authentication_header(URL::URL const&);
@ -93,7 +89,7 @@ private:
URL::URL m_url;
ByteString m_resource;
Method m_method { GET };
Vector<Header> m_headers;
HeaderMap m_headers;
ByteBuffer m_body;
};