From e436c31b97b5e25a6064013ae9deae0f979e95dc Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 26 Sep 2024 16:16:36 -0400 Subject: [PATCH] LibWeb: Ensure WebDriver response headers are exactly to spec We must send a Cache-Control header, which then also requires that we respond with an HTTP/1.1 response (the Pragma cache option is HTTP/1.0). We should also send the Content-Type header using the same casing as is written in the WebDriver spec (lowercase). Both of these are explicitly tested by WPT. --- Userland/Libraries/LibWeb/WebDriver/Client.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.cpp b/Userland/Libraries/LibWeb/WebDriver/Client.cpp index 4868370b908..e7de15f4dd3 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Client.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Client.cpp @@ -293,13 +293,13 @@ ErrorOr Client::send_success_response(JsonValue resu auto content = result.serialized(); StringBuilder builder; - builder.append("HTTP/1.0 200 OK\r\n"sv); + builder.append("HTTP/1.1 200 OK\r\n"sv); builder.append("Server: WebDriver (SerenityOS)\r\n"sv); builder.append("X-Frame-Options: SAMEORIGIN\r\n"sv); builder.append("X-Content-Type-Options: nosniff\r\n"sv); - builder.append("Pragma: no-cache\r\n"sv); if (keep_alive) builder.append("Connection: keep-alive\r\n"sv); + builder.append("Cache-Control: no-cache\r\n"sv); builder.append("Content-Type: application/json; charset=utf-8\r\n"sv); builder.appendff("Content-Length: {}\r\n", content.length()); builder.append("\r\n"sv); @@ -334,8 +334,9 @@ ErrorOr Client::send_error_response(Error const& err result.serialize(content_builder); StringBuilder header_builder; - header_builder.appendff("HTTP/1.0 {} {}\r\n", error.http_status, reason); - header_builder.append("Content-Type: application/json; charset=UTF-8\r\n"sv); + header_builder.appendff("HTTP/1.1 {} {}\r\n", error.http_status, reason); + header_builder.append("Cache-Control: no-cache\r\n"sv); + header_builder.append("Content-Type: application/json; charset=utf-8\r\n"sv); header_builder.appendff("Content-Length: {}\r\n", content_builder.length()); header_builder.append("\r\n"sv);