Skip to content

Commit

Permalink
fix(Headers): lowercase name in Headers.prototype.set (nodejs#1535)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and metcoder95 committed Dec 26, 2022
1 parent 167ae9c commit 5583998
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fetch/headers.js
Expand Up @@ -110,6 +110,7 @@ class HeadersList {
// https://fetch.spec.whatwg.org/#concept-header-list-set
set (name, value) {
this[kHeadersSortedMap] = null
name = name.toLowerCase()

// 1. If list contains name, then set the value of
// the first such header to value and remove the
Expand Down
26 changes: 26 additions & 0 deletions test/fetch/response.js
Expand Up @@ -138,3 +138,29 @@ test('async iterable body', async (t) => {
t.equal(await response.text(), 'abc')
t.end()
})

// https://github.com/nodejs/node/pull/43752#issuecomment-1179678544
test('Modifying headers using Headers.prototype.set', (t) => {
const response = new Response('body', {
headers: {
'content-type': 'test/test',
'Content-Encoding': 'hello/world'
}
})

const response2 = response.clone()

response.headers.set('content-type', 'application/wasm')
response.headers.set('Content-Encoding', 'world/hello')

t.equal(response.headers.get('content-type'), 'application/wasm')
t.equal(response.headers.get('Content-Encoding'), 'world/hello')

response2.headers.delete('content-type')
response2.headers.delete('Content-Encoding')

t.equal(response2.headers.get('content-type'), null)
t.equal(response2.headers.get('Content-Encoding'), null)

t.end()
})

0 comments on commit 5583998

Please sign in to comment.