Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 907d67d

Browse filesBrowse files
deokjinkimRafaelGSS
authored andcommitted
http: refactor to use validateHeaderName
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>
1 parent 36ae3cc commit 907d67d
Copy full SHA for 907d67d

File tree

Expand file treeCollapse file tree

2 files changed

+9
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-6
lines changed
Open diff view settings
Collapse file

‎doc/api/http.md‎

Copy file name to clipboardExpand all lines: doc/api/http.md
+6-1Lines changed: 6 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3657,13 +3657,18 @@ Passing an `AbortSignal` and then calling `abort` on the corresponding
36573657
`AbortController` will behave the same way as calling `.destroy()` on the
36583658
request itself.
36593659

3660-
## `http.validateHeaderName(name)`
3660+
## `http.validateHeaderName(name[, label])`
36613661

36623662
<!-- YAML
36633663
added: v14.3.0
3664+
changes:
3665+
- version: REPLACEME
3666+
pr-url: https://github.com/nodejs/node/pull/46143
3667+
description: The `label` parameter is added.
36643668
-->
36653669

36663670
* `name` {string}
3671+
* `label` {string} Label for error message. **Default:** `'Header name'`.
36673672

36683673
Performs the low-level validations on the provided `name` that are done when
36693674
`res.setHeader(name, value)` is called.
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,9 @@ function matchHeader(self, state, field, value) {
627627
}
628628
}
629629

630-
const validateHeaderName = hideStackFrames((name) => {
630+
const validateHeaderName = hideStackFrames((name, label) => {
631631
if (typeof name !== 'string' || !name || !checkIsHttpToken(name)) {
632-
throw new ERR_INVALID_HTTP_TOKEN('Header name', name);
632+
throw new ERR_INVALID_HTTP_TOKEN(label || 'Header name', name);
633633
}
634634
});
635635

@@ -932,9 +932,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
932932
field = key;
933933
value = headers[key];
934934
}
935-
if (typeof field !== 'string' || !field || !checkIsHttpToken(field)) {
936-
throw new ERR_INVALID_HTTP_TOKEN('Trailer name', field);
937-
}
935+
validateHeaderName(field, 'Trailer name');
938936

939937
// Check if the field must be sent several times
940938
const isArrayValue = ArrayIsArray(value);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.