summaryrefslogtreecommitdiff
path: root/Userland/Services/WebServer
diff options
context:
space:
mode:
author0xbigshaq <57250448+0xbigshaq@users.noreply.github.com>2022-07-29 04:43:40 +0300
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-08-02 21:05:32 +0000
commitaf467344976f784fbb273b089fcb48bd80d674a4 (patch)
tree56f15e970fc151a29624e43330f81c4d021d8217 /Userland/Services/WebServer
parenta4a7efaf5f7688a45a78da92a14b79e2ec11d60c (diff)
downloadserenity-af467344976f784fbb273b089fcb48bd80d674a4.zip
LibHTTP+WebServer: Add querystring support
Split the path from querystring when determining the requested resource.
Diffstat (limited to 'Userland/Services/WebServer')
-rw-r--r--Userland/Services/WebServer/Client.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/Userland/Services/WebServer/Client.cpp b/Userland/Services/WebServer/Client.cpp
index e76376692a..c0fa3541fa 100644
--- a/Userland/Services/WebServer/Client.cpp
+++ b/Userland/Services/WebServer/Client.cpp
@@ -98,6 +98,7 @@ ErrorOr<bool> Client::handle_request(ReadonlyBytes raw_request)
if (!request_or_error.has_value())
return false;
auto& request = request_or_error.value();
+ auto resource_decoded = URL::percent_decode(request.resource());
if constexpr (WEBSERVER_DEBUG) {
dbgln("Got HTTP request: {} {}", request.method_name(), request.resource());
@@ -120,7 +121,7 @@ ErrorOr<bool> Client::handle_request(ReadonlyBytes raw_request)
}
}
- auto requested_path = LexicalPath::join("/"sv, request.resource()).string();
+ auto requested_path = LexicalPath::join("/"sv, resource_decoded).string();
dbgln_if(WEBSERVER_DEBUG, "Canonical requested path: '{}'", requested_path);
StringBuilder path_builder;
@@ -130,7 +131,7 @@ ErrorOr<bool> Client::handle_request(ReadonlyBytes raw_request)
if (Core::File::is_directory(real_path)) {
- if (!request.resource().ends_with('/')) {
+ if (!resource_decoded.ends_with('/')) {
StringBuilder red;
red.append(requested_path);
@@ -362,7 +363,7 @@ ErrorOr<void> Client::send_error_response(unsigned code, HTTP::HttpRequest const
void Client::log_response(unsigned code, HTTP::HttpRequest const& request)
{
- outln("{} :: {:03d} :: {} {}", Core::DateTime::now().to_string(), code, request.method_name(), request.resource());
+ outln("{} :: {:03d} :: {} {}", Core::DateTime::now().to_string(), code, request.method_name(), request.url().serialize().substring(1));
}
bool Client::verify_credentials(Vector<HTTP::HttpRequest::Header> const& headers)