Skip to content

Commit

Permalink
fix: respect when status code is set with res.status (restifyGH-1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
svozza committed Aug 3, 2017
1 parent 25d10f0 commit e111d7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Response.prototype.__send = function __send() {

// Set sane defaults for optional arguments if they were not provided and
// we failed to derive their values
code = code || 200;
code = code || self.statusCode || 200;
headers = headers || {};

// Populate our response object with the derived arguments
Expand Down
12 changes: 12 additions & 0 deletions test/response.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,15 @@ test('GH-951: sendRaw accepts only strings or buffers', function (t) {
// throw away response, we don't need it.
STRING_CLIENT.get(join(LOCALHOST, '/16'));
});

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);
t.end();
});
});

0 comments on commit e111d7d

Please sign in to comment.