summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/_http_outgoing.ts
diff options
context:
space:
mode:
authormash-graz <mash-graz@users.noreply.github.com>2024-03-10 23:46:05 +0100
committerGitHub <noreply@github.com>2024-03-10 22:46:05 +0000
commit16dbbfa64a5d2905580535c52c1db51d1cf5b89f (patch)
tree5cf86fd3955309a86149322dd2664d15b33c31ea /ext/node/polyfills/_http_outgoing.ts
parent0e644503690f23ced5c13c5d3e59592ce1858018 (diff)
fix(node:http) Export `validateHeaderName` and `validateHeaderValue` functions (#22616)
Modify `_http_outgoing.ts` to support the extended signature of `validateHeaderName()` used since node v19.5.0/v18.14.0 by adding the `label` parameter. (see: https://nodejs.org/api/http.html#httpvalidateheadernamename-label) Making both validation functions accessible as public exports of `node:http` Fixes: #22614
Diffstat (limited to 'ext/node/polyfills/_http_outgoing.ts')
-rw-r--r--ext/node/polyfills/_http_outgoing.ts32
1 files changed, 18 insertions, 14 deletions
diff --git a/ext/node/polyfills/_http_outgoing.ts b/ext/node/polyfills/_http_outgoing.ts
index 0cfc070e6..35526a303 100644
--- a/ext/node/polyfills/_http_outgoing.ts
+++ b/ext/node/polyfills/_http_outgoing.ts
@@ -820,21 +820,25 @@ Object.defineProperty(OutgoingMessage.prototype, "_headerNames", {
),
});
-export const validateHeaderName = hideStackFrames((name) => {
- if (typeof name !== "string" || !name || !checkIsHttpToken(name)) {
- throw new ERR_INVALID_HTTP_TOKEN("Header name", name);
- }
-});
+export const validateHeaderName = hideStackFrames(
+ (name: string, label?: string): void => {
+ if (typeof name !== "string" || !name || !checkIsHttpToken(name)) {
+ throw new ERR_INVALID_HTTP_TOKEN(label || "Header name", name);
+ }
+ },
+);
-export const validateHeaderValue = hideStackFrames((name, value) => {
- if (value === undefined) {
- throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
- }
- if (checkInvalidHeaderChar(value)) {
- debug('Header "%s" contains invalid characters', name);
- throw new ERR_INVALID_CHAR("header content", name);
- }
-});
+export const validateHeaderValue = hideStackFrames(
+ (name: string, value: string): void => {
+ if (value === undefined) {
+ throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
+ }
+ if (checkInvalidHeaderChar(value)) {
+ debug('Header "%s" contains invalid characters', name);
+ throw new ERR_INVALID_CHAR("header content", name);
+ }
+ },
+);
export function parseUniqueHeadersOption(headers) {
if (!Array.isArray(headers)) {