Skip to content
Open
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
25 changes: 25 additions & 0 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
const kSetHeader = Symbol('setHeader');
const kAppendHeader = Symbol('appendHeader');
const kAborted = Symbol('aborted');
const kHeadersDistinct = Symbol('kHeadersDistinct');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: for symbols, generally the name doesn't have the k prefix - it's just the meaningful string


let statusMessageWarned = false;
let statusConnectionHeaderWarned = false;
Expand Down Expand Up @@ -323,6 +324,7 @@
this[kRawTrailers] = [];
this[kStream] = stream;
this[kAborted] = false;
this[kHeadersDistinct] = undefined;
stream[kProxySocket] = null;
stream[kRequest] = this;

Expand Down Expand Up @@ -356,6 +358,29 @@
return this[kHeaders];
}

get headersDistinct() {
if (this[kHeadersDistinct] === undefined) {

Check failure on line 362 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 4 spaces but found 2
const distinct = { __proto__: null };

Check failure on line 363 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 6 spaces but found 4

const raw = this[kRawHeaders];

Check failure on line 365 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 6 spaces but found 4

for (let i = 0; i < raw.length; i += 2) {

Check failure on line 367 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 6 spaces but found 4
const name = String(raw[i]).toLowerCase();

Check failure on line 368 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Use `const { String } = primordials;` instead of the global

Check failure on line 368 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 8 spaces but found 6
const value = raw[i + 1];

Check failure on line 369 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 8 spaces but found 6

if (distinct[name] === undefined) {

Check failure on line 371 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 8 spaces but found 6
distinct[name] = [value];

Check failure on line 372 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 10 spaces but found 8
} else {

Check failure on line 373 in lib/internal/http2/compat.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 8 spaces but found 6
distinct[name].push(value);
}
}

this[kHeadersDistinct] = distinct;
}

return this[kHeadersDistinct];
}

get rawHeaders() {
return this[kRawHeaders];
}
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-http2-compat-serverrequest-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ const h2 = require('http2');
assert.strictEqual(rawHeaders[position + 1], value);
}

const headersDistinct = request.headersDistinct;

assert.deepStrictEqual(
headersDistinct,
{
__proto__: null,
':path': ['/foobar'],
':method': ['GET'],
':scheme': ['http'],
':authority': [`localhost:${port}`],
'foo-bar': ['abc123'],
}
);

assert.strictEqual(
headersDistinct,
request.headersDistinct
);

request.url = '/one';
assert.strictEqual(request.url, '/one');

Expand Down
Loading