From 8f2c2f5b7f5615dafacf45f77f16140effe0137a Mon Sep 17 00:00:00 2001
From: tsctx <91457664+tsctx@users.noreply.github.com>
Date: Thu, 25 Apr 2024 05:26:58 +0900
Subject: [PATCH 1/2] Revert "fix casing issue when cloning Headers object
 (#3160)"

This reverts commit 034e3f08009120cdc8e811f7e9d0154062147ccb.
---
 lib/web/fetch/headers.js   |  6 ------
 lib/web/fetch/request.js   |  5 ++---
 test/fetch/headers-case.js | 30 ------------------------------
 3 files changed, 2 insertions(+), 39 deletions(-)
 delete mode 100644 test/fetch/headers-case.js

diff --git a/lib/web/fetch/headers.js b/lib/web/fetch/headers.js
index a1dab1050a8..2235f125c65 100644
--- a/lib/web/fetch/headers.js
+++ b/lib/web/fetch/headers.js
@@ -602,12 +602,6 @@ webidl.converters.HeadersInit = function (V) {
   if (webidl.util.Type(V) === 'Object') {
     const iterator = Reflect.get(V, Symbol.iterator)
 
-    // A work-around to ensure we send the properly-cased Headers when V is a Headers object.
-    // Read https://github.com/nodejs/undici/pull/3159#issuecomment-2075537226 before touching, please.
-    if (!util.types.isProxy(V) && kHeadersList in V && iterator === Headers.prototype.entries) { // Headers object
-      return V[kHeadersList].entries
-    }
-
     if (typeof iterator === 'function') {
       return webidl.converters['sequence<sequence<ByteString>>'](V, iterator.bind(V))
     }
diff --git a/lib/web/fetch/request.js b/lib/web/fetch/request.js
index 60626f06a92..ca12576b1f0 100644
--- a/lib/web/fetch/request.js
+++ b/lib/web/fetch/request.js
@@ -459,9 +459,8 @@ class Request {
       // 4. If headers is a Headers object, then for each header in its header
       // list, append header’s name/header’s value to this’s headers.
       if (headers instanceof HeadersList) {
-        for (const { 0: key, 1: val } of headers) {
-          // Note: The header names are already in lowercase.
-          headersList.append(key, val, true)
+        for (const [key, val] of headers) {
+          headersList.append(key, val)
         }
         // Note: Copy the `set-cookie` meta-data.
         headersList.cookies = headers.cookies
diff --git a/test/fetch/headers-case.js b/test/fetch/headers-case.js
deleted file mode 100644
index bd9770b755f..00000000000
--- a/test/fetch/headers-case.js
+++ /dev/null
@@ -1,30 +0,0 @@
-'use strict'
-
-const { fetch, Headers } = require('../..')
-const { createServer } = require('node:http')
-const { once } = require('node:events')
-const { test } = require('node:test')
-const { tspl } = require('@matteo.collina/tspl')
-
-test('Headers retain keys case-sensitive', async (t) => {
-  const assert = tspl(t, { plan: 3 })
-
-  const server = createServer((req, res) => {
-    assert.ok(req.rawHeaders.includes('Content-Type'))
-
-    res.end()
-  }).listen(0)
-
-  t.after(() => server.close())
-  await once(server, 'listening')
-
-  for (const headers of [
-    new Headers([['Content-Type', 'text/plain']]),
-    { 'Content-Type': 'text/plain' },
-    [['Content-Type', 'text/plain']]
-  ]) {
-    await fetch(`http://localhost:${server.address().port}`, {
-      headers
-    })
-  }
-})

From 1d49f97652d92102b61b739945e5a1586bce24a1 Mon Sep 17 00:00:00 2001
From: tsctx <91457664+tsctx@users.noreply.github.com>
Date: Thu, 25 Apr 2024 05:35:23 +0900
Subject: [PATCH 2/2] test: add

---
 test/fetch/headers.js | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/test/fetch/headers.js b/test/fetch/headers.js
index 00798559e90..ac1183eeded 100644
--- a/test/fetch/headers.js
+++ b/test/fetch/headers.js
@@ -725,6 +725,12 @@ test('Headers.prototype.getSetCookie', async (t) => {
     assert.deepStrictEqual(res.headers.getSetCookie(), ['test=onetwo', 'test=onetwothree'])
     assert.ok('set-cookie' in entries)
   })
+
+  await t.test('When Headers are cloned, so are the cookies (Headers constructor)', () => {
+    const headers = new Headers([['set-cookie', 'a'], ['set-cookie', 'b']])
+
+    assert.deepStrictEqual([...headers], [...new Headers(headers)])
+  })
 })
 
 test('When the value is updated, update the cache', (t) => {
