Procházet zdrojové kódy

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.
Timothy Flynn před 9 měsíci
rodič
revize
e436c31b97
1 změnil soubory, kde provedl 5 přidání a 4 odebrání
  1. 5 4
      Userland/Libraries/LibWeb/WebDriver/Client.cpp

+ 5 - 4
Userland/Libraries/LibWeb/WebDriver/Client.cpp

@@ -293,13 +293,13 @@ ErrorOr<void, Client::WrappedError> Client::send_success_response(JsonValue resu
     auto content = result.serialized<StringBuilder>();
 
     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<void, Client::WrappedError> 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);