1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

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
13 changed files with 35 additions and 13 deletions

View file

@ -64,7 +64,7 @@ OwnPtr<Messages::ProtocolServer::StartDownloadResponse> ClientConnection::handle
auto* protocol = Protocol::find_by_name(url.protocol());
if (!protocol)
return make<Messages::ProtocolServer::StartDownloadResponse>(-1);
auto download = protocol->start_download(*this, url);
auto download = protocol->start_download(*this, url, message.request_headers().entries());
if (!download)
return make<Messages::ProtocolServer::StartDownloadResponse>(-1);
auto id = download->id();

View file

@ -40,7 +40,7 @@ GeminiProtocol::~GeminiProtocol()
{
}
OwnPtr<Download> GeminiProtocol::start_download(ClientConnection& client, const URL& url)
OwnPtr<Download> GeminiProtocol::start_download(ClientConnection& client, const URL& url, const HashMap<String, String>&)
{
Gemini::GeminiRequest request;
request.set_url(url);

View file

@ -35,7 +35,7 @@ public:
GeminiProtocol();
virtual ~GeminiProtocol() override;
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&) override;
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&, const HashMap<String, String>&) override;
};
}

View file

@ -40,11 +40,12 @@ HttpProtocol::~HttpProtocol()
{
}
OwnPtr<Download> HttpProtocol::start_download(ClientConnection& client, const URL& url)
OwnPtr<Download> HttpProtocol::start_download(ClientConnection& client, const URL& url, const HashMap<String, String>& headers)
{
HTTP::HttpRequest request;
request.set_method(HTTP::HttpRequest::Method::GET);
request.set_url(url);
request.set_headers(headers);
auto job = request.schedule();
if (!job)
return nullptr;

View file

@ -35,7 +35,7 @@ public:
HttpProtocol();
virtual ~HttpProtocol() override;
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&) override;
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&, const HashMap<String, String>& headers) override;
};
}

View file

@ -40,11 +40,12 @@ HttpsProtocol::~HttpsProtocol()
{
}
OwnPtr<Download> HttpsProtocol::start_download(ClientConnection& client, const URL& url)
OwnPtr<Download> HttpsProtocol::start_download(ClientConnection& client, const URL& url, const HashMap<String, String>& headers)
{
HTTP::HttpRequest request;
request.set_method(HTTP::HttpRequest::Method::GET);
request.set_url(url);
request.set_headers(headers);
auto job = HTTP::HttpsJob::construct(request);
auto download = HttpsDownload::create_with_job({}, client, (HTTP::HttpsJob&)*job);
job->start();

View file

@ -35,7 +35,7 @@ public:
HttpsProtocol();
virtual ~HttpsProtocol() override;
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&) override;
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&, const HashMap<String, String>& headers) override;
};
}

View file

@ -37,7 +37,7 @@ public:
virtual ~Protocol();
const String& name() const { return m_name; }
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&) = 0;
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&, const HashMap<String, String>& headers) = 0;
static Protocol* find_by_name(const String&);

View file

@ -10,6 +10,6 @@ endpoint ProtocolServer = 9
IsSupportedProtocol(String protocol) => (bool supported)
// Download API
StartDownload(String url) => (i32 download_id)
StartDownload(String url, IPC::Dictionary request_headers) => (i32 download_id)
StopDownload(i32 download_id) => (bool success)
}