From 8d1f78dbd46cc6a5bd97b392c3a24283dcbfc9a6 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Mon, 13 Nov 2023 18:29:47 +0900 Subject: [PATCH 1/5] fix: implement `Headers#delete` correctly --- lib/fetch/headers.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/fetch/headers.js b/lib/fetch/headers.js index f37c5c99e03..cf6f45f267c 100644 --- a/lib/fetch/headers.js +++ b/lib/fetch/headers.js @@ -301,14 +301,10 @@ class Headers { // 6. If this’s header list does not contain name, then // return. - if (!this[kHeadersList].contains(name)) { - return - } - // 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 From 125611ef31b733745d1ef274e4488e959a4b77f1 Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Mon, 13 Nov 2023 18:38:59 +0900 Subject: [PATCH 2/5] fix: HeadersList --- lib/fetch/headers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fetch/headers.js b/lib/fetch/headers.js index cf6f45f267c..29587763bac 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 From 8f12309417d92ccb35542c3df95a6403c524b10c Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Tue, 14 Nov 2023 03:55:56 +0900 Subject: [PATCH 3/5] test: add --- test/fetch/headers.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/fetch/headers.js b/test/fetch/headers.js index c4b4e03d297..d47d6412102 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,14 @@ tap.test('Headers delete', t => { t.throws(() => headers.delete(), 'throws on missing namee') t.throws(() => headers.delete('invalid @ header ? name'), 'throws on invalid name') }) + + 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 => { From ae27be77b648f196808368bcb5f49d6807d5322d Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Tue, 14 Nov 2023 03:59:38 +0900 Subject: [PATCH 4/5] test: add comment --- test/fetch/headers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fetch/headers.js b/test/fetch/headers.js index d47d6412102..6b4b413c277 100644 --- a/test/fetch/headers.js +++ b/test/fetch/headers.js @@ -194,6 +194,7 @@ tap.test('Headers delete', t => { 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' }) From f198341af4c209b4c5aab3ef55f491aeec2cfdad Mon Sep 17 00:00:00 2001 From: tsctx <91457664+tsctx@users.noreply.github.com> Date: Tue, 14 Nov 2023 04:18:02 +0900 Subject: [PATCH 5/5] revert --- lib/fetch/headers.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/fetch/headers.js b/lib/fetch/headers.js index 29587763bac..2971e63746d 100644 --- a/lib/fetch/headers.js +++ b/lib/fetch/headers.js @@ -301,6 +301,10 @@ class Headers { // 6. If this’s header list does not contain name, then // return. + if (!this[kHeadersList].contains(name)) { + return + } + // 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.