diff --git a/lib/fetch/headers.js b/lib/fetch/headers.js index f37c5c99e03..2971e63746d 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 c4b4e03d297..6b4b413c277 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 => {