LibWeb: Assign the Content-Type fetch response header as appropriate

The condition here was inverted.
This commit is contained in:
Timothy Flynn 2024-04-27 10:34:58 -04:00 committed by Andreas Kling
parent b04ef436fa
commit 34b446ab34
Notes: sideshowbarker 2024-07-16 20:31:50 +09:00
3 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,2 @@
text/html
text/plain

View File

@ -0,0 +1,18 @@
<script src="include.js"></script>
<script>
test(() => {
const data = ["<h1>Well hello friends!</h1>"];
const blob = new Blob(data, { type: "text/html" });
const response1 = new Response(blob);
const response2 = new Response(blob, {
headers: {
"Content-Type": "text/plain",
},
});
println(response1.headers.get("Content-Type"));
println(response2.headers.get("Content-Type"));
});
</script>

View File

@ -113,7 +113,7 @@ WebIDL::ExceptionOr<void> Response::initialize_response(ResponseInit const& init
m_response->set_body(body->body);
// 3. If bodys type is non-null and responses header list does not contain `Content-Type`, then append (`Content-Type`, bodys type) to responses 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())),