Skip to content

Commit

Permalink
fix: implement Headers#delete correctly (#2430)
Browse files Browse the repository at this point in the history
* fix: implement `Headers#delete` correctly

* fix: HeadersList

* test: add

* test: add comment

* revert
  • Loading branch information
tsctx authored Nov 14, 2023
1 parent 5555e5e commit ba4ca32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit ba4ca32

Please sign in to comment.