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

WebServer: Allow the user to specify the base directory

This commit makes the WebServer accept a base path to serve.
This makes taking files out of the system significantly more simple
(depending on whom you ask).
This commit is contained in:
AnotherTest 2020-07-11 11:33:22 +04:30 committed by Andreas Kling
parent 7b5ffe67cf
commit 684b04e02a
3 changed files with 20 additions and 6 deletions

View file

@ -38,9 +38,10 @@
namespace WebServer {
Client::Client(NonnullRefPtr<Core::TCPSocket> socket, Core::Object* parent)
Client::Client(NonnullRefPtr<Core::TCPSocket> socket, const String& root, Core::Object* parent)
: Core::Object(parent)
, m_socket(socket)
, m_root_path(root)
{
}
@ -86,7 +87,8 @@ void Client::handle_request(ByteBuffer raw_request)
dbg() << "Canonical requested path: '" << requested_path << "'";
StringBuilder path_builder;
path_builder.append("/www/");
path_builder.append(m_root_path);
path_builder.append('/');
path_builder.append(requested_path);
auto real_path = path_builder.to_string();