diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-21 12:27:42 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-21 12:27:42 +0200 |
commit | 897998017af64a641ddbd82e5d12d08f6bcc2aea (patch) | |
tree | 9dd276bcea06850b4d693083abdaf1184ccbb7db /Libraries/LibHTTP/HttpRequest.cpp | |
parent | 25cfdf3f6790ce9b7650e2a54adf1552826c7a0d (diff) | |
download | serenity-897998017af64a641ddbd82e5d12d08f6bcc2aea.zip |
ProtocolServer: Support request headers
You can now pass a dictionary of request headers when starting a new
download in ProtocolServer.
The HTTP and HTTPS protocol will include the headers in their requests.
Diffstat (limited to 'Libraries/LibHTTP/HttpRequest.cpp')
-rw-r--r-- | Libraries/LibHTTP/HttpRequest.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Libraries/LibHTTP/HttpRequest.cpp b/Libraries/LibHTTP/HttpRequest.cpp index f3ba313cae..075fe55197 100644 --- a/Libraries/LibHTTP/HttpRequest.cpp +++ b/Libraries/LibHTTP/HttpRequest.cpp @@ -71,7 +71,14 @@ ByteBuffer HttpRequest::to_raw_request() const } builder.append(" HTTP/1.1\r\nHost: "); builder.append(m_url.host()); - builder.append("\r\nConnection: close\r\n\r\n"); + builder.append("\r\n"); + for (auto& header : m_headers) { + builder.append(header.name); + builder.append(": "); + builder.append(header.value); + builder.append("\r\n"); + } + builder.append("Connection: close\r\n\r\n"); return builder.to_byte_buffer(); } @@ -181,4 +188,10 @@ Optional<HttpRequest> HttpRequest::from_raw_request(const ByteBuffer& raw_reques return request; } +void HttpRequest::set_headers(const HashMap<String,String>& headers) +{ + for (auto& it : headers) + m_headers.append({ it.key, it.value }); +} + } |