-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc(http): res.write(data) followed by res.end() is not actually equivalent to res.end(data) #26005
Comments
Using res.end() to write result instead of res.write() followed by res.end() will cause node not to use chunked encoding and include Content-Length header. (See nodejs/node#26005) This small distinction is important with some client. For example, Windows 10's MDM enrollment system will not accept chunked response (https://docs.microsoft.com/en-us/windows/client-management/mdm/on-premise-authentication-device-enrollment). This might improve compatibility with some other clients, too. However, there's a small chance that some client may expect the response to be chunked.
Using res.end() to write result instead of res.write() followed by res.end() will cause node not to use chunked encoding and include Content-Length header. (See nodejs/node#26005) This small distinction is important with some client. For example, Windows 10's MDM enrollment system will not accept chunked response (https://docs.microsoft.com/en-us/windows/client-management/mdm/on-premise-authentication-device-enrollment). This might improve compatibility with some other clients, too. However, there's a small chance that some client may expect the response to be chunked. So, I put this behind an option which defaults to enabled and can be disabled if needed.
Using res.end() to write result instead of res.write() followed by res.end() will cause node not to use chunked encoding and include Content-Length header. (See nodejs/node#26005) This small distinction is important with some client. For example, Windows 10's MDM enrollment system will not accept chunked response (https://docs.microsoft.com/en-us/windows/client-management/mdm/on-premise-authentication-device-enrollment). This might improve compatibility with some other clients, too. However, there's a small chance that some client may expect the response to be chunked. So, I put this behind an option which defaults to enabled and can be disabled if needed.
Using res.end() to write result instead of res.write() followed by res.end() will cause node not to use chunked encoding and include Content-Length header. (See nodejs/node#26005) This small distinction is important with some client. For example, Windows 10's MDM enrollment system will not accept chunked response (https://docs.microsoft.com/en-us/windows/client-management/mdm/on-premise-authentication-device-enrollment). This might improve compatibility with some other clients, too. However, there's a small chance that some client may expect the response to be chunked. So, I put this behind an option which defaults to enabled and can be disabled if needed.
@peat-psuwit are you interested in submitting a PR to fix the documentation? |
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. |
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 |
Current behavior was defined in #1062. Before that both cases in your example returned |
Calling `response.end(data)` is not 100% equivalent to calling `response.write(data)` followed by `response.end()`. Fixes: nodejs#26005
Calling `response.end(data)` is not 100% equivalent to calling `response.write(data)` followed by `response.end()`. PR-URL: nodejs#26465 Fixes: nodejs#26005 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Linux (My hostname) 4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
(Xubuntu 18.04)In the document for method
end([data][, encoding][, callback])
of classhttp.ServerResponse
, there's a following text:However, this is not actually true when there's only single
response.write(data)
, demonstrable with the following code:By using
curl -v
, this happens:So, it appears that
response.write(data)
follow byresponse.end()
cause Node.js to use chunked encoding, whileresponse.end(data)
cause Node.js to not using chunked encoding and includeContent-Length
header. This small distinction is important with some client. For example, Windows 10's MDM enrollment system will not accept chunked response.The text was updated successfully, but these errors were encountered: