1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:38:10 +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:
Andreas Kling 2020-09-28 11:55:26 +02:00
parent cfafd4d52d
commit 2946a684ef
21 changed files with 78 additions and 26 deletions

View file

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