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: implement Headers#delete correctly #2430

Merged
merged 5 commits into from
Nov 14, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class HeadersList {
this.cookies = null
}

return this[kHeadersMap].delete(name)
this[kHeadersMap].delete(name)
}

// https://fetch.spec.whatwg.org/#concept-header-list-get
Expand Down Expand Up @@ -308,7 +308,7 @@ class Headers {
// 7. Delete name from this’s header list.
// 8. If this’s guard is "request-no-cors", then remove
// privileged no-CORS request headers from this.
return this[kHeadersList].delete(name)
this[kHeadersList].delete(name)
}

// https://fetch.spec.whatwg.org/#dom-headers-get
Expand Down
11 changes: 10 additions & 1 deletion test/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ tap.test('Headers append', t => {
})

tap.test('Headers delete', t => {
t.plan(3)
t.plan(4)

t.test('deletes valid header entry from instance', t => {
t.plan(3)
Expand Down Expand Up @@ -193,6 +193,15 @@ tap.test('Headers delete', t => {
t.throws(() => headers.delete(), 'throws on missing namee')
t.throws(() => headers.delete('invalid @ header ? name'), 'throws on invalid name')
})

// https://github.com/nodejs/undici/issues/2429
t.test('`Headers#delete` returns undefined', t => {
t.plan(2)
const headers = new Headers({ test: 'test' })

t.same(headers.delete('test'), undefined)
t.same(headers.delete('test2'), undefined)
})
})

tap.test('Headers get', t => {
Expand Down
Loading