Bug Report
Restify Version
5.0.1
Node.js Version
Node 8
Expected behaviour
When using res.status in a route, I expect the status code set there to be the one returned when
hitting the route.
Actual behaviour
The route always returns a 200.
Repro case
Here's the test I have in my branch:
test('GH-1429: setting code with res.status not respected', function (t) {
SERVER.get('/404', function (req, res, next) {
res.status(404);
res.send(null);
});
CLIENT.get(join(LOCALHOST, '/404'), function (err, _, res) {
t.equal(res.statusCode, 404); // always returns a 200
t.end();
});
});
Cause
The offending code is here:
https://github.com/restify/node-restify/blob/5.x/lib/response.js#L307
https://github.com/restify/node-restify/blob/5.x/lib/response.js#L311
On line 307 if code is undefined it gets set to 200 and then on line 311 that overwrites self.statusCode even if it has already been set.
Are you willing and able to fix this?
Yes. In fact, I've already fixed it on my fork.
Bug Report
Restify Version
5.0.1
Node.js Version
Node 8
Expected behaviour
When using
res.statusin a route, I expect the status code set there to be the one returned whenhitting the route.
Actual behaviour
The route always returns a 200.
Repro case
Here's the test I have in my branch:
Cause
The offending code is here:
https://github.com/restify/node-restify/blob/5.x/lib/response.js#L307
https://github.com/restify/node-restify/blob/5.x/lib/response.js#L311
On line 307 if
codeis undefined it gets set to 200 and then on line 311 that overwritesself.statusCodeeven if it has already been set.Are you willing and able to fix this?
Yes. In fact, I've already fixed it on my fork.