diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 3abe9ba2ac6f82..73371de2dafb0b 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -552,7 +552,8 @@ class Http2ServerResponse extends Stream { } getHeaders() { - return { ...this[kHeaders] }; + const headers = ObjectCreate(null); + return ObjectAssign(headers, this[kHeaders]); } hasHeader(name) { diff --git a/test/parallel/test-http2-compat-serverresponse-headers.js b/test/parallel/test-http2-compat-serverresponse-headers.js index 14e480f611857a..96875e1bce3400 100644 --- a/test/parallel/test-http2-compat-serverresponse-headers.js +++ b/test/parallel/test-http2-compat-serverresponse-headers.js @@ -102,11 +102,13 @@ server.listen(0, common.mustCall(function() { response.setHeader(real, expectedValue); const expectedHeaderNames = [real]; assert.deepStrictEqual(response.getHeaderNames(), expectedHeaderNames); - const expectedHeaders = { [real]: expectedValue }; + const expectedHeaders = Object.create(null); + expectedHeaders[real] = expectedValue; assert.deepStrictEqual(response.getHeaders(), expectedHeaders); response.getHeaders()[fake] = fake; assert.strictEqual(response.hasHeader(fake), false); + assert.strictEqual(Object.getPrototypeOf(response.getHeaders()), null); assert.strictEqual(response.sendDate, true); response.sendDate = false;