-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Closed
Labels
httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.
Description
- Version: 12.16.1
- Platform: Windows
- Subsystem: http
response.writeHead(statusCode[, statusMessage][, headers])
works as expected if statusMessage is omitted, supplying a default value.
However, if undefined is passed as a placeholder then it unexpectedly ignores the headers argument.
Why would I want this? Imagine a function like:
function send({ statusCode, statusMessage, headers, body } = { statusCode: 404 }, res) {
return new Promise((resolve, reject) => {
res.writeHead(statusCode, statusMessage, headers)
.end(body)
.on('finish', resolve)
.on('error', reject)
})
}You can see I depend on a single signature to work whether statusMessage is supplied or not. Otherwise, I have to:
if (statusMessage)
res.writeHead(statusCode, statusMessage, headers)
else
res.writeHead(statusCode, headers)Not the end of the world, but it lacks elegance.
Maybe this is not a bug, but wrong expectations?
Perhaps. But this expectation aligns with how javascript default parameters behave.
Metadata
Metadata
Assignees
Labels
httpIssues or PRs related to the http subsystem.Issues or PRs related to the http subsystem.