Skip to content

Commit

Permalink
doc: remove warning from response.writeHead
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cecchi authored and targos committed Apr 28, 2020
1 parent 02f99d2 commit 38e51d3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -1705,12 +1705,10 @@ const server = http.createServer((req, res) => {
});
```

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

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

0 comments on commit 38e51d3

Please sign in to comment.