Skip to content

Conversation

@simov
Copy link
Contributor

@simov simov commented Mar 8, 2021

Fixes: #37641

As discussed here #37641 (comment) I'm submitting a patch to expose the raw header names being sent with the request.

I didn't updated the documentation because I'm not sure about the process for deprecating things since DEP0066 was introduced in v12 and this is v15.

@nodejs-github-bot nodejs-github-bot added http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels Mar 8, 2021
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

Could you add documentation please?

@aduh95 aduh95 added the semver-minor PRs that contain new features and should be released in the next minor version. label Mar 8, 2021
@benjamingr
Copy link
Member

This looks like a good start - documentation and a test would be the next steps :)

@simov
Copy link
Contributor Author

simov commented Mar 9, 2021

@aduh95, @benjamingr, I updated the deprecation message, and added docs for the getRawHeaderNames in ClientRequest. However, I'm noticing that documentation for the rest of the methods there is missing. It should be identical to the http.ServerResponse for all headers related methods.

@benjamingr there is a test in test-http-mutable-headers.js, that's the only place I've found that have tests related to those methods.

@benjamingr
Copy link
Member

that's the only place I've found that have tests related to those methods.

That sounds reasonable - if you'd like I think there is value in adding a few more cases there - otherwise the test you added is probably fine for now and we can add more tests in a future PR.

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

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

Generally LGTM, ping @nodejs/http

@benjamingr benjamingr added the notable-change PRs with changes that should be highlighted in changelogs. label Mar 9, 2021
@simov
Copy link
Contributor Author

simov commented Mar 10, 2021

@benjamingr I added one additional assertion for testing the new method on the response object.

@aduh95, @mcollina all comments were addressed.

Comment on lines 610 to 613
const headers = Array(ObjectKeys(headersMap).length);

if (headersMap !== null) {
const values = ObjectValues(headersMap);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid calling %Object.keys% here? We can get the same info from %Object.values%, right? Also, if headersMap is null, wouldn't %Object.keys% throw?

Suggested change
const headers = Array(ObjectKeys(headersMap).length);
if (headersMap !== null) {
const values = ObjectValues(headersMap);
if (headerMap == null) return [];
const values = ObjectValues(headersMap);
const headers = Array(values.length);
{

Copy link
Contributor

Choose a reason for hiding this comment

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

We can also save the length to a variable to reuse it in the for loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, pushed 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed the length comment, but I can add that if needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Btw values.length is stored in l so that's only one assignment + accessing the property added.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can either:

  1. store the value in a variable and read the variable to avoid looking up the property value several time.
  2. access the property each time and rely on the compiler optimisations.

The current implementation access the property twice before putting its value in a variable, that seems unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current implementation access the property twice before putting its value in a variable, that seems unnecessary.

Exactly. Not sure if one additional property access call on top changes anything, but I can update the code if you want. Your call.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I'd prefer to see either of the approach described in my comment above.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

@Trott Trott force-pushed the feature-raw-headers branch from ecb76b9 to b99d01f Compare March 20, 2021 18:37
Fixes: nodejs#37641

PR-URL: nodejs#37660
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@Trott Trott force-pushed the feature-raw-headers branch from b99d01f to 4686cb5 Compare March 20, 2021 18:38
@Trott Trott merged commit 4686cb5 into nodejs:master Mar 20, 2021
@Trott
Copy link
Member

Trott commented Mar 20, 2021

Landed in 4686cb5

Thanks for reporting the issue and doing the work to fix it! 🎉

@ruyadorno ruyadorno mentioned this pull request Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc: DEP0066 is slightly incorrect

6 participants