Skip to content

Commit

Permalink
fix: respect when status code is set with res.status (GH-1429) (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
svozza authored and sean3z committed Aug 14, 2017
1 parent e9c49f0 commit 5abc067
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
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
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 5abc067

Please sign in to comment.