Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Headers): lowercase name in Headers.prototype.set #1535

Merged
merged 1 commit into from Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
})