Skip to content
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: calling ServerResponse.writeHead multiple times? #36721

Closed
ronag opened this issue Jan 1, 2021 · 2 comments · Fixed by #45508
Closed

http: calling ServerResponse.writeHead multiple times? #36721

ronag opened this issue Jan 1, 2021 · 2 comments · Fixed by #45508
Labels
http Issues or PRs related to the http subsystem.

Comments

@ronag
Copy link
Member

ronag commented Jan 1, 2021

Looking through the code it seems a bit undefined what happens if writeHead is called multiple times. Especially in the case where the headers have already been sent. I would expect at least the former to error but that does not seem to be the case.

@ronag ronag added the http Issues or PRs related to the http subsystem. label Jan 1, 2021
@ronag
Copy link
Member Author

ronag commented Jan 1, 2021

Another potential problem with writeHead is that headers passed through this function are not accessible through getHeader. I'm not sure this is documented.

@marco-ippolito
Copy link
Member

marco-ippolito commented Nov 17, 2022

Another potential problem with writeHead is that headers passed through this function are not accessible through getHeader. I'm not sure this is documented.

It seems to be documented here

and also under under response.getHeader

If response.writeHead() method is called and this method has not been called, it will directly write the supplied header values onto the network channel without caching internally, and the response.getHeader() on the header will not yield the expected result. If progressive population of headers is desired with potential future retrieval and modification, use response.setHeader() instead of response.writeHead().

nodejs-github-bot pushed a commit that referenced this issue Nov 24, 2022
PR-URL: #45508
Fixes: #36721
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito added a commit to marco-ippolito/node that referenced this issue Nov 24, 2022
PR-URL: nodejs#45508
Fixes: nodejs#36721
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants