You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
doc(http): res.write(data) followed by res.end() is not actually equivalent to res.end(data) #26005
$ curl -v http://localhost:9001/ # response.write(data) follow by response.end()
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9001 (#0)
> GET / HTTP/1.1
> Host: localhost:9001
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 08 Feb 2019 10:26:25 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
Hello!
* Connection #0 to host localhost left intact
$ curl -v http://localhost:9002/ # response.end(data)
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9002 (#0)
> GET / HTTP/1.1
> Host: localhost:9002
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 08 Feb 2019 10:26:31 GMT
< Connection: keep-alive
< Content-Length: 7
<
Hello!
* Connection #0 to host localhost left intact
$
So, it appears that response.write(data) follow by response.end() cause Node.js to use chunked encoding, while response.end(data) cause Node.js to not using chunked encoding and include Content-Length header. This small distinction is important with some client. For example, Windows 10's MDM enrollment system will not accept chunked response.
Hmm, I'm not sure how I should change the document. Also, after I read some comment in the source I start to wonder if the current behavior is not an intended behavior.
Activity
server: send response to client with res.end()
server: add option enableChunkedEncoding
server: add option enableChunkedEncoding
server: add option enableChunkedEncoding (#1043)
lpinca commentedon Mar 4, 2019
@peat-psuwit are you interested in submitting a PR to fix the documentation?
peat-psuwit commentedon Mar 4, 2019
Hmm, I'm not sure how I should change the document. Also, after I read some comment in the source I start to wonder if the current behavior is not an intended behavior.
lpinca commentedon Mar 4, 2019
I think current behavior is intended, but the sentence you quoted is misleading. Perhaps remove it or reword it to match current behavior?
cc: @nodejs/http
lpinca commentedon Mar 4, 2019
Current behavior was defined in #1062. Before that both cases in your example returned
Transfer-Encoding: chunked.doc: fix misleading sentence in http.md
doc: fix misleading sentence in http.md
doc: fix misleading sentence in http.md
doc: fix misleading sentence in http.md
doc: fix misleading sentence in http.md