From 962d6993814e2400c23a8a5af96d79fcb4faf1f8 Mon Sep 17 00:00:00 2001 From: Dinesh0007000 <164600789+Dinesh0007000@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:22:21 +0530 Subject: [PATCH 1/5] doc: clarify http.request supports headers as array This PR updates the documentation for `http.request()` to clarify that the `headers` option can also be an array of key-value pairs, similar to `response.writeHead`. Fixes: https://github.com/nodejs/node/issues/57986 --- doc/api/http.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/api/http.md b/doc/api/http.md index 21d8f412af303f..a3796b6bae133c 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -3820,7 +3820,9 @@ changes: * `family` {number} IP address family to use when resolving `host` or `hostname`. Valid values are `4` or `6`. When unspecified, both IP v4 and v6 will be used. - * `headers` {Object} An object containing request headers. + * `headers` {Object | Array} Request headers to send with the request. This can be: + * An object like `{ 'Content-Type': 'application/json' }`, or + * An array of key-value pairs like `[ 'Content-Type', 'text/plain', 'X-Custom', 'yes' ]`, similar to how headers are passed to `response.writeHead()`. * `hints` {number} Optional [`dns.lookup()` hints][]. * `host` {string} A domain name or IP address of the server to issue the request to. **Default:** `'localhost'`. From 0182ac9a154c986f13ee28f1118d18960a240e94 Mon Sep 17 00:00:00 2001 From: Dinesh0007000 <164600789+Dinesh0007000@users.noreply.github.com> Date: Fri, 20 Jun 2025 19:19:08 +0530 Subject: [PATCH 2/5] doc: clarify headers array format in http.request options Added a detailed explanation for how the 'headers' option in http.request can also be passed as a flat array of alternating header names and values. This provides clarity for beginners and aligns with the format used in response.writeHead() and request.rawHeaders. --- doc/api/http.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index a3796b6bae133c..c933468a043079 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -3821,8 +3821,18 @@ changes: `hostname`. Valid values are `4` or `6`. When unspecified, both IP v4 and v6 will be used. * `headers` {Object | Array} Request headers to send with the request. This can be: - * An object like `{ 'Content-Type': 'application/json' }`, or - * An array of key-value pairs like `[ 'Content-Type', 'text/plain', 'X-Custom', 'yes' ]`, similar to how headers are passed to `response.writeHead()`. + * An object like `{ 'Content-Type': 'application/json' }`. + * A flat array of header name/value pairs like + `[ 'Content-Type', 'text/plain', 'X-Custom', 'yes' ]`. This format is + the same as used in [`response.writeHead()`][] and exposed in + [`request.rawHeaders`][]. + + When passing `headers` as an array, it must be a flat list of alternating + header names and values. Nested arrays or objects are not supported in this + form. This array format is identical to that used in [`response.writeHead()`][] + and [`request.rawHeaders`][], and is often useful when working with raw header + data directly. + * `hints` {number} Optional [`dns.lookup()` hints][]. * `host` {string} A domain name or IP address of the server to issue the request to. **Default:** `'localhost'`. @@ -4331,3 +4341,6 @@ A browser-compatible implementation of [`WebSocket`][]. [`writable.uncork()`]: stream.md#writableuncork [`writable.write()`]: stream.md#writablewritechunk-encoding-callback [initial delay]: net.md#socketsetkeepaliveenable-initialdelay +[`response.writeHead()`]: https://nodejs.org/api/http.html#responsewriteheadstatuscode-statusmessage-headers +[`request.rawHeaders`]: https://nodejs.org/api/http.html#requestrawheaders + From 03e463a547a8c55b7dc8e3019e8d9b033bc50def Mon Sep 17 00:00:00 2001 From: Dinesh0007000 <164600789+Dinesh0007000@users.noreply.github.com> Date: Sat, 21 Jun 2025 08:12:08 +0530 Subject: [PATCH 3/5] fix: address markdown linting issues and link formatting - Removed duplicate definition of [`response.writeHead()`] as it already exists earlier in the file. - Updated [`request.rawHeaders`] link to be relative (#requestrawheaders) instead of using an absolute URL. These fixes resolve markdown linting issues flagged by the CI and ensure consistency with documentation standards. --- doc/api/http.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index c933468a043079..6fde0151dba1ae 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -4341,6 +4341,4 @@ A browser-compatible implementation of [`WebSocket`][]. [`writable.uncork()`]: stream.md#writableuncork [`writable.write()`]: stream.md#writablewritechunk-encoding-callback [initial delay]: net.md#socketsetkeepaliveenable-initialdelay -[`response.writeHead()`]: https://nodejs.org/api/http.html#responsewriteheadstatuscode-statusmessage-headers -[`request.rawHeaders`]: https://nodejs.org/api/http.html#requestrawheaders - +[`request.rawHeaders`]: #requestrawheaders From c1ccfc596f5e10edf2fd950bb0c8b20ffacd9720 Mon Sep 17 00:00:00 2001 From: Dinesh Karthik Date: Tue, 24 Jun 2025 03:07:49 +0000 Subject: [PATCH 4/5] temp: prepare for rebase --- doc/api/http.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index 6fde0151dba1ae..3bb99fdd37f28b 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -3822,17 +3822,14 @@ changes: v6 will be used. * `headers` {Object | Array} Request headers to send with the request. This can be: * An object like `{ 'Content-Type': 'application/json' }`. - * A flat array of header name/value pairs like - `[ 'Content-Type', 'text/plain', 'X-Custom', 'yes' ]`. This format is - the same as used in [`response.writeHead()`][] and exposed in - [`request.rawHeaders`][]. - - When passing `headers` as an array, it must be a flat list of alternating - header names and values. Nested arrays or objects are not supported in this - form. This array format is identical to that used in [`response.writeHead()`][] - and [`request.rawHeaders`][], and is often useful when working with raw header - data directly. - + * A flat array of header name/value pairs like `[ 'Content-Type', 'text/plain', 'X-Custom', + 'yes' ]`. This format is the same as used in [`response.writeHead()`][] and exposed in + request.rawHeaders. + When passing `headers` as an array, it must be a flat list of alternating + header names and values. Nested arrays or objects are not supported in this + form. This array format is identical to that used in [`response.writeHead()`][] + and request.rawHeaders, and is often useful when working with raw header + data directly. * `hints` {number} Optional [`dns.lookup()` hints][]. * `host` {string} A domain name or IP address of the server to issue the request to. **Default:** `'localhost'`. @@ -4341,4 +4338,3 @@ A browser-compatible implementation of [`WebSocket`][]. [`writable.uncork()`]: stream.md#writableuncork [`writable.write()`]: stream.md#writablewritechunk-encoding-callback [initial delay]: net.md#socketsetkeepaliveenable-initialdelay -[`request.rawHeaders`]: #requestrawheaders From 9d3526a82129812829cbf927dcded5a2047c9eb0 Mon Sep 17 00:00:00 2001 From: Dinesh0007000 <164600789+Dinesh0007000@users.noreply.github.com> Date: Fri, 20 Jun 2025 12:22:21 +0530 Subject: [PATCH 5/5] doc: clarify http.request supports headers as array This PR updates the documentation for `http.request()` to clarify that the `headers` option can also be an array of key-value pairs, similar to `response.writeHead`. Fixes: https://github.com/nodejs/node/issues/57986 doc: clarify headers array format in http.request options Added a detailed explanation for how the 'headers' option in http.request can also be passed as a flat array of alternating header names and values. This provides clarity for beginners and aligns with the format used in response.writeHead() and request.rawHeaders. fix: address markdown linting issues and link formatting - Removed duplicate definition of [`response.writeHead()`] as it already exists earlier in the file. - Updated [`request.rawHeaders`] link to be relative (#requestrawheaders) instead of using an absolute URL. These fixes resolve markdown linting issues flagged by the CI and ensure consistency with documentation standards. temp: prepare for rebase --- doc/api/http.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index 3bb99fdd37f28b..93a43105c51075 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -3824,11 +3824,11 @@ changes: * An object like `{ 'Content-Type': 'application/json' }`. * A flat array of header name/value pairs like `[ 'Content-Type', 'text/plain', 'X-Custom', 'yes' ]`. This format is the same as used in [`response.writeHead()`][] and exposed in - request.rawHeaders. + `request.rawHeaders`. When passing `headers` as an array, it must be a flat list of alternating header names and values. Nested arrays or objects are not supported in this form. This array format is identical to that used in [`response.writeHead()`][] - and request.rawHeaders, and is often useful when working with raw header + and `request.rawHeaders`, and is often useful when working with raw header data directly. * `hints` {number} Optional [`dns.lookup()` hints][]. * `host` {string} A domain name or IP address of the server to issue the