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.
This commit is contained in:
Andreas Kling 2020-05-21 12:27:42 +02:00
parent 25cfdf3f67
commit 897998017a
Notes: sideshowbarker 2024-07-19 06:17:37 +09:00
13 changed files with 35 additions and 13 deletions

View file

@ -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 });
}
}