Skip to content

Commit

Permalink
🤖 Merge PR #62632 node: Add validateHeaderName/validateHeaderValue to…
Browse files Browse the repository at this point in the history
… v14 and v16 by @meyfa

This patch iterates on PR #62456, which added `validateHeaderName()` and
`validateHeaderValue()` to `@types/node`. These methods exist since
Node.js version 14.3.0, hence they are now included in the v14 and v16
variants of `http.d.ts` as well.
  • Loading branch information
meyfa committed Oct 10, 2022
1 parent 6531b97 commit 6597463
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 10 deletions.
12 changes: 7 additions & 5 deletions types/node/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1541,23 +1541,25 @@ declare module 'http' {
*/
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;

/**
* Performs the low-level validations on the provided name that are done when res.setHeader(name, value) is called.
* Passing illegal value as name will result in a TypeError being thrown, identified by code: 'ERR_INVALID_HTTP_TOKEN'.
* Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
* @param name Header name
* @since v14.3.0
*/
function validateHeaderName(name: string): void;
/**
* Performs the low-level validations on the provided value that are done when res.setHeader(name, value) is called.
* Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as value will result in a TypeError being thrown.
* - Undefined value error is identified by code: 'ERR_HTTP_INVALID_HEADER_VALUE'.
* - Invalid value character error is identified by code: 'ERR_INVALID_CHAR'.
* - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
* - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
* @param name Header name
* @param value Header value
* @since v14.3.0
*/
function validateHeaderValue(name: string, value: string): void;

let globalAgent: Agent;
/**
* Read-only property specifying the maximum allowed size of HTTP headers in bytes.
Expand Down
12 changes: 7 additions & 5 deletions types/node/ts4.8/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1541,23 +1541,25 @@ declare module 'http' {
*/
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;

/**
* Performs the low-level validations on the provided name that are done when res.setHeader(name, value) is called.
* Passing illegal value as name will result in a TypeError being thrown, identified by code: 'ERR_INVALID_HTTP_TOKEN'.
* Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
* @param name Header name
* @since v14.3.0
*/
function validateHeaderName(name: string): void;
/**
* Performs the low-level validations on the provided value that are done when res.setHeader(name, value) is called.
* Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as value will result in a TypeError being thrown.
* - Undefined value error is identified by code: 'ERR_HTTP_INVALID_HEADER_VALUE'.
* - Invalid value character error is identified by code: 'ERR_INVALID_CHAR'.
* - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
* - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
* @param name Header name
* @param value Header value
* @since v14.3.0
*/
function validateHeaderValue(name: string, value: string): void;

let globalAgent: Agent;
/**
* Read-only property specifying the maximum allowed size of HTTP headers in bytes.
Expand Down
19 changes: 19 additions & 0 deletions types/node/v14/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,25 @@ declare module 'http' {
): ClientRequest;
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;

/**
* Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
* @param name Header name
* @since v14.3.0
*/
function validateHeaderName(name: string): void;
/**
* Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as value will result in a TypeError being thrown.
* - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
* - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
* @param name Header name
* @param value Header value
* @since v14.3.0
*/
function validateHeaderValue(name: string, value: string): void;

let globalAgent: Agent;

/**
Expand Down
5 changes: 5 additions & 0 deletions types/node/v14/test/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,8 @@ import * as dns from 'node:dns';
http.request({ lookup: dns.lookup });
http.request({ lookup: (hostname, options, cb) => { cb(null, '', 1); } });
}

{
http.validateHeaderName('Location');
http.validateHeaderValue('Location', '/');
}
19 changes: 19 additions & 0 deletions types/node/v14/ts4.8/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,25 @@ declare module 'http' {
): ClientRequest;
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;

/**
* Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
* @param name Header name
* @since v14.3.0
*/
function validateHeaderName(name: string): void;
/**
* Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as value will result in a TypeError being thrown.
* - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
* - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
* @param name Header name
* @param value Header value
* @since v14.3.0
*/
function validateHeaderValue(name: string, value: string): void;

let globalAgent: Agent;

/**
Expand Down
5 changes: 5 additions & 0 deletions types/node/v14/ts4.8/test/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,8 @@ import * as dns from 'node:dns';
http.request({ lookup: dns.lookup });
http.request({ lookup: (hostname, options, cb) => { cb(null, '', 1); } });
}

{
http.validateHeaderName('Location');
http.validateHeaderValue('Location', '/');
}
19 changes: 19 additions & 0 deletions types/node/v16/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,25 @@ declare module 'http' {
*/
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;

/**
* Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
* @param name Header name
* @since v14.3.0
*/
function validateHeaderName(name: string): void;
/**
* Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as value will result in a TypeError being thrown.
* - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
* - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
* @param name Header name
* @param value Header value
* @since v14.3.0
*/
function validateHeaderValue(name: string, value: string): void;

let globalAgent: Agent;
/**
* Read-only property specifying the maximum allowed size of HTTP headers in bytes.
Expand Down
5 changes: 5 additions & 0 deletions types/node/v16/test/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,8 @@ import * as dns from 'node:dns';
http.request({ lookup: dns.lookup });
http.request({ lookup: (hostname, options, cb) => { cb(null, '', 1); } });
}

{
http.validateHeaderName('Location');
http.validateHeaderValue('Location', '/');
}
19 changes: 19 additions & 0 deletions types/node/v16/ts4.8/http.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,25 @@ declare module 'http' {
*/
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;

/**
* Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
* @param name Header name
* @since v14.3.0
*/
function validateHeaderName(name: string): void;
/**
* Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
* Passing illegal value as value will result in a TypeError being thrown.
* - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
* - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
* @param name Header name
* @param value Header value
* @since v14.3.0
*/
function validateHeaderValue(name: string, value: string): void;

let globalAgent: Agent;
/**
* Read-only property specifying the maximum allowed size of HTTP headers in bytes.
Expand Down
5 changes: 5 additions & 0 deletions types/node/v16/ts4.8/test/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,8 @@ import * as dns from 'node:dns';
http.request({ lookup: dns.lookup });
http.request({ lookup: (hostname, options, cb) => { cb(null, '', 1); } });
}

{
http.validateHeaderName('Location');
http.validateHeaderValue('Location', '/');
}

0 comments on commit 6597463

Please sign in to comment.