From ba4ca327843de62a83c1f9c32acc303bd6b8545f Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Tue, 14 Nov 2023 09:04:40 +0900 Subject: [PATCH] fix: implement `Headers#delete` correctly (#2430) * fix: implement `Headers#delete` correctly * fix: HeadersList * test: add * test: add comment * revert --- lib/fetch/headers.js | 4 ++-- test/fetch/headers.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/fetch/headers.js b/lib/fetch/headers.js index 035560428bc..cfdc8868efa 100644 --- a/lib/fetch/headers.js +++ b/lib/fetch/headers.js @@ -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 @@ -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 diff --git a/test/fetch/headers.js b/test/fetch/headers.js index 5da1a1ded1f..48461103d78 100644 --- a/test/fetch/headers.js +++ b/test/fetch/headers.js @@ -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) @@ -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 => {