-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
http.ServerResponse.writeHead() can be called multiple times for a single response #8446
Comments
@nodejs/http |
@nodejs/http @nodejs/documentation @nodejs/streams It would be great to get a determination on this:
|
I don't know exactly how to categorize this, as maybe What I am getting using the server in the example is:
I think the correct behavior should be for the second Also, the following text is obscure to me:
I do not understand what is being asked here, as multiple |
Please note that 1xx status codes can be sent multiple times; the 2xx-5xx codes must only be sent once. See my related issue #27921. |
this has been fixed by #45508 @ShogunPanda |
@marco-ippolito Thanks, closing this! |
Despite the API documentation's statement that http.ServerResponse.writeHead() "must only be called once on a message", multiple calls to the method simply modify the response header without complaint.
To test this (verified in 6.4, 4.x, and 0.10): Create an instance of http.Server whose request listener writes the response header more than once, then calls write() or end() on the response.
Additionally, calling writeHead() after a write() on the response object will modify the header of any subsequent response messages sent to the client with write(), or cause the server to send one final empty response with the modified head if end() is called without any additional messages being sent.
Example code:
require('http').createServer(function(req,res){res.writeHead(500,'Internal Server Error');res.write('Hello World!');setImmediate(function(){res.writeHead(200);res.end();});}).listen(3000);
I'm not sure if this is unintended behavior or simply misleading naming/documentation, but one might assume that the first call to writeHead() would cause any subsequent calls to either throw an error or fail silently.
The text was updated successfully, but these errors were encountered: