Skip to content

Commit 8e14f76

Browse files
kimownevanlucas
authored andcommitted
doc: use Buffer.byteLength for Content-Length
As the description in http.md: > If the body contains higher coded characters then Buffer.byteLength() should be used to determine the number of bytes in a given encoding. PR-URL: #7274 Reviewed-By: Brian White <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jackson Tian <[email protected]>
1 parent 5d03bdd commit 8e14f76

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

doc/api/http.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ Example:
859859
```js
860860
var body = 'hello world';
861861
response.writeHead(200, {
862-
'Content-Length': body.length,
862+
'Content-Length': Buffer.byteLength(body),
863863
'Content-Type': 'text/plain' });
864864
```
865865

@@ -1181,7 +1181,7 @@ var options = {
11811181
method: 'POST',
11821182
headers: {
11831183
'Content-Type': 'application/x-www-form-urlencoded',
1184-
'Content-Length': postData.length
1184+
'Content-Length': Buffer.byteLength(postData)
11851185
}
11861186
};
11871187

0 commit comments

Comments
 (0)