-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
http: refactor to use validateHeaderName
#46143
http: refactor to use validateHeaderName
#46143
Conversation
Remove duplicate implementation by using validateHeaderName.
Review requested:
|
lib/_http_outgoing.js
Outdated
if (typeof field !== 'string' || !field || !checkIsHttpToken(field)) { | ||
throw new ERR_INVALID_HTTP_TOKEN('Trailer name', field); | ||
} | ||
validateHeaderName(field); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function uses 'header name' instead of 'trailer name' in the error message which is probably not as helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Unless you make the error message customizable we cannot make this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your concern. So added label
parameter to validateHeaderName
. PTAL.
To customize error message, add label parameter
lib/_http_outgoing.js
Outdated
@@ -628,9 +628,9 @@ function matchHeader(self, state, field, value) { | |||
} | |||
} | |||
|
|||
const validateHeaderName = hideStackFrames((name) => { | |||
const validateHeaderName = hideStackFrames((name, label = 'Header name') => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not work the way you want, as it will be undefined
if the second parameter is explicitly passed as undefined
. Move it to a ||
conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied your suggestion. Thank you for your help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW it's not correct, the default value is used no matter if undefined
is passed explicitly or not.
((param = 'default value') => console.log(param))(); // 'default value'
((param = 'default value') => console.log(param))(undefined); // 'default value'
((param = 'default value') => console.log(param))(null); // null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Co-authored-by: mscdex <mscdex@users.noreply.github.com>
Commit Queue failed- Loading data for nodejs/node/pull/46143 ✔ Done loading data for nodejs/node/pull/46143 ----------------------------------- PR info ------------------------------------ Title http: refactor to use `validateHeaderName` (#46143) Author Deokjin Kim (@deokjinkim) Branch deokjinkim:230110_http_validate_header_name -> nodejs:main Labels http, author ready Commits 4 - http: refactor to use `validateHeaderName` - add `label` parameter to validateHeaderName - use `||` instead of default parameter - describe default value of label as string Committers 2 - Deokjin Kim - GitHub PR-URL: https://github.com/nodejs/node/pull/46143 Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/46143 Reviewed-By: Matteo Collina Reviewed-By: Antoine du Hamel -------------------------------------------------------------------------------- ℹ This PR was created on Mon, 09 Jan 2023 15:27:15 GMT ✔ Approvals: 2 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/46143#pullrequestreview-1243743249 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/46143#pullrequestreview-1251349454 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2023-01-17T11:17:12Z: https://ci.nodejs.org/job/node-test-pull-request/49007/ - Querying data for job/node-test-pull-request/49007/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 46143 From https://github.com/nodejs/node * branch refs/pull/46143/merge -> FETCH_HEAD ✔ Fetched commits as 15d673dfbe02..254670133f08 -------------------------------------------------------------------------------- Auto-merging lib/_http_outgoing.js [main b408cb431e] http: refactor to use `validateHeaderName` Author: Deokjin Kim Date: Tue Jan 10 00:25:41 2023 +0900 2 files changed, 1 insertion(+), 4 deletions(-) Auto-merging doc/api/http.md Auto-merging lib/_http_outgoing.js [main d9ccab9f46] add `label` parameter to validateHeaderName Author: Deokjin Kim Date: Tue Jan 10 08:52:34 2023 +0900 3 files changed, 10 insertions(+), 4 deletions(-) Auto-merging lib/_http_outgoing.js [main 03b6d46f31] use `||` instead of default parameter Author: Deokjin Kim Date: Tue Jan 10 23:05:34 2023 +0900 1 file changed, 2 insertions(+), 2 deletions(-) Auto-merging doc/api/http.md [main 431d56ea02] describe default value of label as string Author: Deokjin Kim Date: Thu Jan 12 08:11:46 2023 +0900 1 file changed, 1 insertion(+), 1 deletion(-) ✔ Patches applied There are 4 commits in the PR. Attempting autorebase. Rebasing (2/8)https://github.com/nodejs/node/actions/runs/3939661314 |
Landed in f461a4c |
Remove duplicate implementation by using validateHeaderName. PR-URL: nodejs#46143 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Remove duplicate implementation by using validateHeaderName. PR-URL: #46143 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Remove duplicate implementation by using validateHeaderName. PR-URL: #46143 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Remove duplicate implementation by using validateHeaderName. PR-URL: #46143 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Remove duplicate implementation by using validateHeaderName.