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

res.setHeader and res.writeHead should return this #25935

Closed
qubyte opened this issue Feb 5, 2019 · 2 comments
Closed

res.setHeader and res.writeHead should return this #25935

qubyte opened this issue Feb 5, 2019 · 2 comments
Labels
feature request Issues that request new features to be added to Node.js. http Issues or PRs related to the http subsystem.

Comments

@qubyte
Copy link
Contributor

qubyte commented Feb 5, 2019

Is your feature request related to a problem? Please describe.
When working with vanilla node HTTP servers, I frequently make the mistake that res.setHeader and (more often) res.writeHead return this, allowing a .end to be appended. For example:

res.writeHead(201, headers).end(body);

This is an error, since writeHead returns undefined.

Describe the solution you'd like
I'd like to have res.setHeader and res.writeHead return this to allow chaining. The same behaviour should be added to the HTTP/2 compatibility module too. I'm happy to put together a pull request if you are open to the change.

Describe alternatives you've considered
I sometimes define a helper function to do this, but it's clunky.

@bnoordhuis bnoordhuis added http Issues or PRs related to the http subsystem. feature request Issues that request new features to be added to Node.js. labels Feb 5, 2019
@bnoordhuis
Copy link
Member

Seems like an uncontroversial change. Pull request welcome, I'd say.

@qubyte
Copy link
Contributor Author

qubyte commented Feb 5, 2019

Thanks. I'll work on this this evening (UTC).

addaleax pushed a commit that referenced this issue Feb 9, 2019
Fixes: #25935

PR-URL: #25974
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
targos pushed a commit that referenced this issue Feb 10, 2019
Fixes: #25935

PR-URL: #25974
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
targos pushed a commit that referenced this issue Feb 10, 2019
Fixes: #25935

PR-URL: #25974
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
BethGriggs pushed a commit that referenced this issue Oct 7, 2019
Fixes: #25935

PR-URL: #25974
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
BethGriggs pushed a commit that referenced this issue Oct 7, 2019
Fixes: #25935

PR-URL: #25974
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

No branches or pull requests

2 participants