From ce80188d6f0dc2c89584ab31200d1047abc7d874 Mon Sep 17 00:00:00 2001 From: Max Wipfli Date: Sat, 29 May 2021 21:54:35 +0200 Subject: 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. --- Userland/Libraries/LibHTTP/HttpRequest.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Userland/Libraries/LibHTTP/HttpRequest.cpp') 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::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; -- cgit v1.2.3