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.
This commit is contained in:
parent
c7857f3572
commit
ce80188d6f
Notes:
sideshowbarker
2024-07-18 17:03:46 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/ce80188d6f0 Pull-request: https://github.com/SerenityOS/serenity/pull/7478 Reviewed-by: https://github.com/awesomekling
1 changed files with 6 additions and 6 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue