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 3 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
4 changes: 3 additions & 1 deletion lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ class Http2ServerResponse extends Stream {
}

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

hasHeader(name) {
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-http2-compat-serverresponse-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ 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(response.hasHeader(fake), true);
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved

assert.strictEqual(response.sendDate, true);
response.sendDate = false;
Expand Down