-
Notifications
You must be signed in to change notification settings - Fork 30k
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: improve errors thrown in header validation #16718
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,12 +40,18 @@ let statusMessageWarned = false; | |
// close as possible to the current require('http') API | ||
|
||
function assertValidHeader(name, value) { | ||
if (name === '' || typeof name !== 'string') | ||
throw new errors.TypeError('ERR_INVALID_HTTP_TOKEN', 'Header name', name); | ||
if (isPseudoHeader(name)) | ||
throw new errors.Error('ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'); | ||
if (value === undefined || value === null) | ||
throw new errors.TypeError('ERR_HTTP2_INVALID_HEADER_VALUE'); | ||
let err; | ||
if (name === '' || typeof name !== 'string') { | ||
err = new errors.TypeError('ERR_INVALID_HTTP_TOKEN', 'Header name', name); | ||
} else if (isPseudoHeader(name)) { | ||
err = new errors.Error('ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'); | ||
} else if (value === undefined || value === null) { | ||
err = new errors.TypeError('ERR_HTTP2_INVALID_HEADER_VALUE', value, name); | ||
} | ||
if (err !== undefined) { | ||
Error.captureStackTrace(err, assertValidHeader); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a particular reason to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lpinca I don't think that frame adds more value to the stacktrace because you can easily tell which line it would be by the error thrown, and the error codes themselves are clear enough to show the reason. Adding one more frame just expose more internal details that the user should not worry about.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, but it should be inferred and it requires a little more effort. Internal details are useful for everyone when debugging. Anyway no problem, I can live with it :) |
||
throw err; | ||
} | ||
} | ||
|
||
function isPseudoHeader(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.
Uh, accidental...can be fixed later.