From a1f0ebb2aa7cfa48a91972e4f0a19a5a910f1903 Mon Sep 17 00:00:00 2001 From: jakecastelli <959672929@qq.com> Date: Mon, 10 Jun 2024 01:24:07 +0930 Subject: [PATCH 1/2] doc, http: add `rejectNonStandardBodyWrites` option, clear its behaviour --- doc/api/http.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index a41ec8838c8257..6f0ecd15022b3a 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -2427,8 +2427,10 @@ it will switch to implicit header mode and flush the implicit headers. This sends a chunk of the response body. This method may be called multiple times to provide successive parts of the body. -Writing to the body is not allowed when the request method or response status -do not support content. If an attempt is made to write to the body for a +If `rejectNonStandardBodyWrites` is set to true in `createServer` +then writing to the body is not allowed when the request method or response +status do not support content. +If an attempt is made to write to the body for a HEAD request or as part of a `204` or `304`response, a synchronous `Error` with the code `ERR_HTTP_BODY_NOT_ALLOWED` is thrown. @@ -3571,6 +3573,9 @@ changes: * `uniqueHeaders` {Array} A list of response headers that should be sent only once. If the header's value is an array, the items will be joined using `; `. + * `rejectNonStandardBodyWrites` {boolean} If set to `true`, an error is thrown + when writing to an HTTP response which does not have a body. + **Default:** `false`. * `requestListener` {Function} From 1112d9752552586619d69068f96836968d1aced7 Mon Sep 17 00:00:00 2001 From: jakecastelli <959672929@qq.com> Date: Mon, 10 Jun 2024 01:31:30 +0930 Subject: [PATCH 2/2] fixup! --- doc/api/http.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index 6f0ecd15022b3a..0427dfff6123cb 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -2429,8 +2429,7 @@ be called multiple times to provide successive parts of the body. If `rejectNonStandardBodyWrites` is set to true in `createServer` then writing to the body is not allowed when the request method or response -status do not support content. -If an attempt is made to write to the body for a +status do not support content. If an attempt is made to write to the body for a HEAD request or as part of a `204` or `304`response, a synchronous `Error` with the code `ERR_HTTP_BODY_NOT_ALLOWED` is thrown.