1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:18:11 +00:00

WebServer: Move server configuration into WebServer::Configuration

This moves the configuration of the web server, which currently only
consists of the root path, into a new class, Configuration. Since the
configuration is global and not per client, it is accessed by a
singleton getter.

This change simplifies future extensions of the configurable parameters.
This commit is contained in:
Max Wipfli 2021-06-06 16:51:37 +02:00 committed by Andreas Kling
parent 2d18d3f329
commit e77ca79897
6 changed files with 65 additions and 9 deletions

View file

@ -5,7 +5,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Client.h"
#include <AK/Base64.h>
#include <AK/Debug.h>
#include <AK/LexicalPath.h>
@ -21,16 +20,17 @@
#include <LibCore/MimeData.h>
#include <LibHTTP/HttpRequest.h>
#include <LibHTTP/HttpResponse.h>
#include <WebServer/Client.h>
#include <WebServer/Configuration.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
namespace WebServer {
Client::Client(NonnullRefPtr<Core::TCPSocket> socket, String const& root, Core::Object* parent)
Client::Client(NonnullRefPtr<Core::TCPSocket> socket, Core::Object* parent)
: Core::Object(parent)
, m_socket(socket)
, m_root_path(root)
{
}
@ -84,8 +84,7 @@ void Client::handle_request(ReadonlyBytes raw_request)
dbgln_if(WEBSERVER_DEBUG, "Canonical requested path: '{}'", requested_path);
StringBuilder path_builder;
path_builder.append(m_root_path);
path_builder.append('/');
path_builder.append(Configuration::the().root_path());
path_builder.append(requested_path);
auto real_path = path_builder.to_string();