Skip to content

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

Closed
@qubyte

Description

@qubyte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions