mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 22:07:35 +00:00
ProtocolServer+LibWeb: Support more detailed HTTP requests
This patch adds the ability for ProtocolServer clients to specify which HTTP method to use, and also to include an optional HTTP request body.
This commit is contained in:
parent
cfafd4d52d
commit
2946a684ef
21 changed files with 78 additions and 26 deletions
|
@ -66,7 +66,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, message.request_headers().entries());
|
||||
auto download = protocol->start_download(*this, message.method(), url, message.request_headers().entries(), message.request_body().to_byte_buffer());
|
||||
if (!download)
|
||||
return make<Messages::ProtocolServer::StartDownloadResponse>(-1);
|
||||
auto id = download->id();
|
||||
|
|
|
@ -40,7 +40,7 @@ GeminiProtocol::~GeminiProtocol()
|
|||
{
|
||||
}
|
||||
|
||||
OwnPtr<Download> GeminiProtocol::start_download(ClientConnection& client, const URL& url, const HashMap<String, String>&)
|
||||
OwnPtr<Download> GeminiProtocol::start_download(ClientConnection& client, const String&, const URL& url, const HashMap<String, String>&, const ByteBuffer&)
|
||||
{
|
||||
Gemini::GeminiRequest request;
|
||||
request.set_url(url);
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
GeminiProtocol();
|
||||
virtual ~GeminiProtocol() override;
|
||||
|
||||
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&, const HashMap<String, String>&) override;
|
||||
virtual OwnPtr<Download> start_download(ClientConnection&, const String& method, const URL&, const HashMap<String, String>&, const ByteBuffer& request_body) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -40,12 +40,16 @@ HttpProtocol::~HttpProtocol()
|
|||
{
|
||||
}
|
||||
|
||||
OwnPtr<Download> HttpProtocol::start_download(ClientConnection& client, const URL& url, const HashMap<String, String>& headers)
|
||||
OwnPtr<Download> HttpProtocol::start_download(ClientConnection& client, const String& method, const URL& url, const HashMap<String, String>& headers, const ByteBuffer& request_body)
|
||||
{
|
||||
HTTP::HttpRequest request;
|
||||
request.set_method(HTTP::HttpRequest::Method::GET);
|
||||
if (method.equals_ignoring_case("post"))
|
||||
request.set_method(HTTP::HttpRequest::Method::POST);
|
||||
else
|
||||
request.set_method(HTTP::HttpRequest::Method::GET);
|
||||
request.set_url(url);
|
||||
request.set_headers(headers);
|
||||
request.set_body(request_body);
|
||||
auto job = request.schedule();
|
||||
if (!job)
|
||||
return nullptr;
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
HttpProtocol();
|
||||
virtual ~HttpProtocol() override;
|
||||
|
||||
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&, const HashMap<String, String>& headers) override;
|
||||
virtual OwnPtr<Download> start_download(ClientConnection&, const String& method, const URL&, const HashMap<String, String>& headers, const ByteBuffer& request_body) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -40,12 +40,16 @@ HttpsProtocol::~HttpsProtocol()
|
|||
{
|
||||
}
|
||||
|
||||
OwnPtr<Download> HttpsProtocol::start_download(ClientConnection& client, const URL& url, const HashMap<String, String>& headers)
|
||||
OwnPtr<Download> HttpsProtocol::start_download(ClientConnection& client, const String& method, const URL& url, const HashMap<String, String>& headers, const ByteBuffer& request_body)
|
||||
{
|
||||
HTTP::HttpRequest request;
|
||||
request.set_method(HTTP::HttpRequest::Method::GET);
|
||||
if (method.equals_ignoring_case("post"))
|
||||
request.set_method(HTTP::HttpRequest::Method::POST);
|
||||
else
|
||||
request.set_method(HTTP::HttpRequest::Method::GET);
|
||||
request.set_url(url);
|
||||
request.set_headers(headers);
|
||||
request.set_body(request_body);
|
||||
auto job = HTTP::HttpsJob::construct(request);
|
||||
auto download = HttpsDownload::create_with_job({}, client, (HTTP::HttpsJob&)*job);
|
||||
job->start();
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
HttpsProtocol();
|
||||
virtual ~HttpsProtocol() override;
|
||||
|
||||
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&, const HashMap<String, String>& headers) override;
|
||||
virtual OwnPtr<Download> start_download(ClientConnection&, const String& method, const URL&, const HashMap<String, String>& headers, const ByteBuffer& request_body) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
virtual ~Protocol();
|
||||
|
||||
const String& name() const { return m_name; }
|
||||
virtual OwnPtr<Download> start_download(ClientConnection&, const URL&, const HashMap<String, String>& headers) = 0;
|
||||
virtual OwnPtr<Download> start_download(ClientConnection&, const String& method, const URL&, const HashMap<String, String>& headers, const ByteBuffer& request_body) = 0;
|
||||
|
||||
static Protocol* find_by_name(const String&);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ endpoint ProtocolServer = 9
|
|||
IsSupportedProtocol(String protocol) => (bool supported)
|
||||
|
||||
// Download API
|
||||
StartDownload(URL url, IPC::Dictionary request_headers) => (i32 download_id)
|
||||
StartDownload(String method, URL url, IPC::Dictionary request_headers, String request_body) => (i32 download_id)
|
||||
StopDownload(i32 download_id) => (bool success)
|
||||
SetCertificate(i32 download_id, String certificate, String key) => (bool success)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue