Skip to content

Commit 95cd771

Browse files
cecchiBridgeAR
authored andcommitted
doc: remove warning from response.writeHead
The example referenced as being potentially unsafe specifies Content-Length correctly. PR-URL: #32700 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
1 parent a1178b6 commit 95cd771

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

doc/api/http.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1713,12 +1713,10 @@ const server = http.createServer((req, res) => {
17131713
});
17141714
```
17151715

1716-
`Content-Length` is given in bytes not characters. The above example
1717-
works because the string `'hello world'` contains only single byte characters.
1718-
If the body contains higher coded characters then `Buffer.byteLength()`
1719-
should be used to determine the number of bytes in a given encoding.
1720-
And Node.js does not check whether `Content-Length` and the length of the body
1721-
which has been transmitted are equal or not.
1716+
`Content-Length` is given in bytes, not characters. Use
1717+
[`Buffer.byteLength()`][] to determine the length of the body in bytes. Node.js
1718+
does not check whether `Content-Length` and the length of the body which has
1719+
been transmitted are equal or not.
17221720

17231721
Attempting to set a header field name or value that contains invalid characters
17241722
will result in a [`TypeError`][] being thrown.
@@ -2388,6 +2386,7 @@ not abort the request or do anything besides add a `'timeout'` event.
23882386
[`'response'`]: #http_event_response
23892387
[`'upgrade'`]: #http_event_upgrade
23902388
[`Agent`]: #http_class_http_agent
2389+
[`Buffer.byteLength()`]: buffer.html#buffer_class_method_buffer_bytelength_string_encoding
23912390
[`Duplex`]: stream.html#stream_class_stream_duplex
23922391
[`TypeError`]: errors.html#errors_class_typeerror
23932392
[`URL`]: url.html#url_the_whatwg_url_api

0 commit comments

Comments
 (0)