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 e620de6

Browse filesBrowse files
deokjinkimjuanarbol
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 94605b1 commit e620de6
Copy full SHA for e620de6

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
@@ -3619,13 +3619,18 @@ Passing an `AbortSignal` and then calling `abort` on the corresponding
36193619
`AbortController` will behave the same way as calling `.destroy()` on the
36203620
request itself.
36213621

3622-
## `http.validateHeaderName(name)`
3622+
## `http.validateHeaderName(name[, label])`
36233623

36243624
<!-- YAML
36253625
added: v14.3.0
3626+
changes:
3627+
- version: REPLACEME
3628+
pr-url: https://github.com/nodejs/node/pull/46143
3629+
description: The `label` parameter is added.
36263630
-->
36273631

36283632
* `name` {string}
3633+
* `label` {string} Label for error message. **Default:** `'Header name'`.
36293634

36303635
Performs the low-level validations on the provided `name` that are done when
36313636
`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
@@ -628,9 +628,9 @@ function matchHeader(self, state, field, value) {
628628
}
629629
}
630630

631-
const validateHeaderName = hideStackFrames((name) => {
631+
const validateHeaderName = hideStackFrames((name, label) => {
632632
if (typeof name !== 'string' || !name || !checkIsHttpToken(name)) {
633-
throw new ERR_INVALID_HTTP_TOKEN('Header name', name);
633+
throw new ERR_INVALID_HTTP_TOKEN(label || 'Header name', name);
634634
}
635635
});
636636

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

940938
// Check if the field must be sent several times
941939
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.