diff --git a/Services/WebServer/Client.cpp b/Services/WebServer/Client.cpp index 37bafda5609..833757b8189 100644 --- a/Services/WebServer/Client.cpp +++ b/Services/WebServer/Client.cpp @@ -25,12 +25,13 @@ */ #include "Client.h" -#include #include #include +#include #include #include #include +#include #include #include #include @@ -122,15 +123,17 @@ void Client::handle_request(ByteBuffer raw_request) return; } - send_response(file->read_all(), request); + send_response(file->read_all(), request, Core::guess_mime_type_based_on_filename(request.url())); } -void Client::send_response(StringView response, const HTTP::HttpRequest& request) +void Client::send_response(StringView response, const HTTP::HttpRequest& request, const String& content_type) { StringBuilder builder; builder.append("HTTP/1.0 200 OK\r\n"); builder.append("Server: WebServer (SerenityOS)\r\n"); - builder.append("Content-Type: text/html\r\n"); + builder.append("Content-Type: "); + builder.append(content_type); + builder.append("\r\n"); builder.append("\r\n"); m_socket->write(builder.to_string()); @@ -201,7 +204,7 @@ void Client::handle_directory_listing(const String& requested_path, const String builder.append("\n"); builder.append("\n"); - send_response(builder.to_string(), request); + send_response(builder.to_string(), request, "text/html"); } void Client::send_error_response(unsigned code, const StringView& message, const HTTP::HttpRequest& request) diff --git a/Services/WebServer/Client.h b/Services/WebServer/Client.h index d7791b3898d..6b078bb5684 100644 --- a/Services/WebServer/Client.h +++ b/Services/WebServer/Client.h @@ -42,7 +42,7 @@ private: Client(NonnullRefPtr, const String&, Core::Object* parent); void handle_request(ByteBuffer); - void send_response(StringView, const HTTP::HttpRequest&); + void send_response(StringView, const HTTP::HttpRequest&, const String& content_type); void send_redirect(StringView redirect, const HTTP::HttpRequest& request); void send_error_response(unsigned code, const StringView& message, const HTTP::HttpRequest&); void die();