Skip to content

Commit 38e51d3

Browse files
cecchitargos
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 02f99d2 commit 38e51d3

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
@@ -1705,12 +1705,10 @@ const server = http.createServer((req, res) => {
17051705
});
17061706
```
17071707

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

17151713
Attempting to set a header field name or value that contains invalid characters
17161714
will result in a [`TypeError`][] being thrown.
@@ -2346,6 +2344,7 @@ not abort the request or do anything besides add a `'timeout'` event.
23462344
[`'response'`]: #http_event_response
23472345
[`'upgrade'`]: #http_event_upgrade
23482346
[`Agent`]: #http_class_http_agent
2347+
[`Buffer.byteLength()`]: buffer.html#buffer_class_method_buffer_bytelength_string_encoding
23492348
[`Duplex`]: stream.html#stream_class_stream_duplex
23502349
[`TypeError`]: errors.html#errors_class_typeerror
23512350
[`URL`]: url.html#url_the_whatwg_url_api

0 commit comments

Comments
 (0)