summaryrefslogtreecommitdiff
path: root/Services
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-28 11:55:26 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-28 11:55:26 +0200
commit2946a684efd1d3c34148d16121b118574b6a9132 (patch)
tree0c541334f692056dda692329d781979a18693ceb /Services
parentcfafd4d52da0ce04231cdeadc93a9d6764cceb8b (diff)
downloadserenity-2946a684efd1d3c34148d16121b118574b6a9132.zip
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.
Diffstat (limited to 'Services')
-rw-r--r--Services/ProtocolServer/ClientConnection.cpp2
-rw-r--r--Services/ProtocolServer/GeminiProtocol.cpp2
-rw-r--r--Services/ProtocolServer/GeminiProtocol.h2
-rw-r--r--Services/ProtocolServer/HttpProtocol.cpp8
-rw-r--r--Services/ProtocolServer/HttpProtocol.h2
-rw-r--r--Services/ProtocolServer/HttpsProtocol.cpp8
-rw-r--r--Services/ProtocolServer/HttpsProtocol.h2
-rw-r--r--Services/ProtocolServer/Protocol.h2
-rw-r--r--Services/ProtocolServer/ProtocolServer.ipc2
9 files changed, 19 insertions, 11 deletions
diff --git a/Services/ProtocolServer/ClientConnection.cpp b/Services/ProtocolServer/ClientConnection.cpp
index beaa55c4e1..86cc6344ce 100644
--- a/Services/ProtocolServer/ClientConnection.cpp
+++ b/Services/ProtocolServer/ClientConnection.cpp
@@ -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();
diff --git a/Services/ProtocolServer/GeminiProtocol.cpp b/Services/ProtocolServer/GeminiProtocol.cpp
index 9bc61d54aa..f1167ecd61 100644
--- a/Services/ProtocolServer/GeminiProtocol.cpp
+++ b/Services/ProtocolServer/GeminiProtocol.cpp
@@ -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);
diff --git a/Services/ProtocolServer/GeminiProtocol.h b/Services/ProtocolServer/GeminiProtocol.h
index e3f28bf57d..f9ed21cca3 100644
--- a/Services/ProtocolServer/GeminiProtocol.h
+++ b/Services/ProtocolServer/GeminiProtocol.h
@@ -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;
};
}
diff --git a/Services/ProtocolServer/HttpProtocol.cpp b/Services/ProtocolServer/HttpProtocol.cpp
index 7eaa51287c..f6b618d4b0 100644
--- a/Services/ProtocolServer/HttpProtocol.cpp
+++ b/Services/ProtocolServer/HttpProtocol.cpp
@@ -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;
diff --git a/Services/ProtocolServer/HttpProtocol.h b/Services/ProtocolServer/HttpProtocol.h
index ee0c0f5f3b..aa9601b8ce 100644
--- a/Services/ProtocolServer/HttpProtocol.h
+++ b/Services/ProtocolServer/HttpProtocol.h
@@ -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;
};
}
diff --git a/Services/ProtocolServer/HttpsProtocol.cpp b/Services/ProtocolServer/HttpsProtocol.cpp
index ab1181cb69..3de9ca8e2b 100644
--- a/Services/ProtocolServer/HttpsProtocol.cpp
+++ b/Services/ProtocolServer/HttpsProtocol.cpp
@@ -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();
diff --git a/Services/ProtocolServer/HttpsProtocol.h b/Services/ProtocolServer/HttpsProtocol.h
index 92f72e8729..9cb0ce190b 100644
--- a/Services/ProtocolServer/HttpsProtocol.h
+++ b/Services/ProtocolServer/HttpsProtocol.h
@@ -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;
};
}
diff --git a/Services/ProtocolServer/Protocol.h b/Services/ProtocolServer/Protocol.h
index 13cff2e7bb..035b56cb6e 100644
--- a/Services/ProtocolServer/Protocol.h
+++ b/Services/ProtocolServer/Protocol.h
@@ -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&);
diff --git a/Services/ProtocolServer/ProtocolServer.ipc b/Services/ProtocolServer/ProtocolServer.ipc
index e819eb3234..4cf1204520 100644
--- a/Services/ProtocolServer/ProtocolServer.ipc
+++ b/Services/ProtocolServer/ProtocolServer.ipc
@@ -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)
}