Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
http: refactor to use validateHeaderName
Remove duplicate implementation by using validateHeaderName.
  • Loading branch information
deokjinkim committed Jan 9, 2023
commit d8ab8742a8eb0945d242db0b4bc78f5ecfd52f25
4 changes: 1 addition & 3 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
field = key;
value = headers[key];
}
if (typeof field !== 'string' || !field || !checkIsHttpToken(field)) {
throw new ERR_INVALID_HTTP_TOKEN('Trailer name', field);
}
validateHeaderName(field);
Copy link
Contributor

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.

Copy link
Contributor

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.

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 understand your concern. So added label parameter to validateHeaderName. PTAL.


// Check if the field must be sent several times
const isArrayValue = ArrayIsArray(value);
Expand Down
1 change: 0 additions & 1 deletion test/parallel/test-http-outgoing-proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ assert.throws(() => {
}, {
code: 'ERR_INVALID_HTTP_TOKEN',
name: 'TypeError',
message: 'Trailer name must be a valid HTTP token ["あ"]'
});

assert.throws(() => {
Expand Down