summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibHTTP/HttpRequest.cpp
diff options
context:
space:
mode:
authorMax Wipfli <mail@maxwipfli.ch>2021-05-29 21:54:35 +0200
committerAndreas Kling <kling@serenityos.org>2021-06-01 09:28:05 +0200
commitce80188d6f0dc2c89584ab31200d1047abc7d874 (patch)
treec3d28204135f5c11bdb050c91056f44f3eab9a2a /Userland/Libraries/LibHTTP/HttpRequest.cpp
parentc7857f35729ac898d4efcb3e50ccefce6f4db9bb (diff)
downloadserenity-ce80188d6f0dc2c89584ab31200d1047abc7d874.zip
LibHTTP: Percent encode/decode request URI
This percent encodes/decodes the request URI when creating or parsing raw HTTP requests. This is necessary because AK::URL now contains percent decoded data, meaning we have to re-encode it for creating raw requests.
Diffstat (limited to 'Userland/Libraries/LibHTTP/HttpRequest.cpp')
-rw-r--r--Userland/Libraries/LibHTTP/HttpRequest.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Libraries/LibHTTP/HttpRequest.cpp b/Userland/Libraries/LibHTTP/HttpRequest.cpp
index b642a17930..32e1c3fbc9 100644
--- a/Userland/Libraries/LibHTTP/HttpRequest.cpp
+++ b/Userland/Libraries/LibHTTP/HttpRequest.cpp
@@ -37,13 +37,13 @@ ByteBuffer HttpRequest::to_raw_request() const
StringBuilder builder;
builder.append(method_name());
builder.append(' ');
- if (!m_url.path().is_empty())
- builder.append(m_url.path());
- else
- builder.append('/');
+ // NOTE: The percent_encode is so that e.g. spaces are properly encoded.
+ auto path = m_url.path();
+ VERIFY(!path.is_empty());
+ builder.append(URL::percent_encode(m_url.path(), URL::PercentEncodeSet::EncodeURI));
if (!m_url.query().is_empty()) {
builder.append('?');
- builder.append(m_url.query());
+ builder.append(URL::percent_encode(m_url.query(), URL::PercentEncodeSet::EncodeURI));
}
builder.append(" HTTP/1.1\r\nHost: ");
builder.append(m_url.host());
@@ -163,7 +163,7 @@ Optional<HttpRequest> HttpRequest::from_raw_request(ReadonlyBytes raw_request)
else
return {};
- request.m_resource = resource;
+ request.m_resource = URL::percent_decode(resource);
request.m_headers = move(headers);
return request;