Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect when status code is set with res.status (GH-1429) #1440

Merged
merged 3 commits into from Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});