Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: [compat api] use Object.create(null) for getHeaders #33188

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ class Http2ServerResponse extends Stream {
}

getHeaders() {
return { ...this[kHeaders] };
rexagod marked this conversation as resolved.
Show resolved Hide resolved
const headers = ObjectCreate(null);
return ObjectAssign(headers, this[kHeaders]);
}

hasHeader(name) {
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-http2-compat-serverresponse-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down