From 34b446ab34daa3edf641d0051d0526c06e2037c8 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 27 Apr 2024 10:34:58 -0400 Subject: [PATCH] LibWeb: Assign the Content-Type fetch response header as appropriate The condition here was inverted. --- .../expected/fetch-response-content-type.txt | 2 ++ .../input/fetch-response-content-type.html | 18 ++++++++++++++++++ Userland/Libraries/LibWeb/Fetch/Response.cpp | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/fetch-response-content-type.txt create mode 100644 Tests/LibWeb/Text/input/fetch-response-content-type.html diff --git a/Tests/LibWeb/Text/expected/fetch-response-content-type.txt b/Tests/LibWeb/Text/expected/fetch-response-content-type.txt new file mode 100644 index 00000000000..26b1f59734c --- /dev/null +++ b/Tests/LibWeb/Text/expected/fetch-response-content-type.txt @@ -0,0 +1,2 @@ +text/html +text/plain diff --git a/Tests/LibWeb/Text/input/fetch-response-content-type.html b/Tests/LibWeb/Text/input/fetch-response-content-type.html new file mode 100644 index 00000000000..a809b5555a8 --- /dev/null +++ b/Tests/LibWeb/Text/input/fetch-response-content-type.html @@ -0,0 +1,18 @@ + + diff --git a/Userland/Libraries/LibWeb/Fetch/Response.cpp b/Userland/Libraries/LibWeb/Fetch/Response.cpp index 839ee6f3133..4acc5c24b87 100644 --- a/Userland/Libraries/LibWeb/Fetch/Response.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Response.cpp @@ -113,7 +113,7 @@ WebIDL::ExceptionOr Response::initialize_response(ResponseInit const& init m_response->set_body(body->body); // 3. If body’s type is non-null and response’s header list does not contain `Content-Type`, then append (`Content-Type`, body’s type) to response’s header list. - if (body->type.has_value() && m_response->header_list()->contains("Content-Type"sv.bytes())) { + if (body->type.has_value() && !m_response->header_list()->contains("Content-Type"sv.bytes())) { auto header = Infrastructure::Header { .name = MUST(ByteBuffer::copy("Content-Type"sv.bytes())), .value = MUST(ByteBuffer::copy(body->type->span())),