diff --git a/lib/response.js b/lib/response.js index a6537ca3e..80d8ebd10 100644 --- a/lib/response.js +++ b/lib/response.js @@ -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 diff --git a/test/response.test.js b/test/response.test.js index 47c852619..1bbf236fb 100644 --- a/test/response.test.js +++ b/test/response.test.js @@ -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(); + }); +});