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

http: include provided status code in range error #11221

Merged
merged 1 commit into from
Feb 9, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ ServerResponse.prototype._implicitHeader = function _implicitHeader() {

ServerResponse.prototype.writeHead = writeHead;
function writeHead(statusCode, reason, obj) {
var originalStatusCode = statusCode;

statusCode |= 0;
if (statusCode < 100 || statusCode > 999)
throw new RangeError(`Invalid status code: ${statusCode}`);
throw new RangeError(`Invalid status code: ${originalStatusCode}`);

if (typeof reason === 'string') {
// writeHead(statusCode, reasonPhrase[, headers])
Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-http-response-statuscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ const server = http.Server(common.mustCall(function(req, res) {
case 1:
assert.throws(common.mustCall(() => {
res.writeHead(Infinity);
}), createErrorMessage(0));
}), createErrorMessage(Infinity));
break;
case 2:
assert.throws(common.mustCall(() => {
res.writeHead(NaN);
}), createErrorMessage(0));
}), createErrorMessage(NaN));
break;
case 3:
assert.throws(common.mustCall(() => {
res.writeHead({});
}), createErrorMessage(0));
}), createErrorMessage('\\[object Object\\]'));
break;
case 4:
assert.throws(common.mustCall(() => {
Expand All @@ -45,37 +45,37 @@ const server = http.Server(common.mustCall(function(req, res) {
case 6:
assert.throws(common.mustCall(() => {
res.writeHead('1000');
}), createErrorMessage(1000));
}), createErrorMessage('1000'));
break;
case 7:
assert.throws(common.mustCall(() => {
res.writeHead(null);
}), createErrorMessage(0));
}), createErrorMessage(null));
break;
case 8:
assert.throws(common.mustCall(() => {
res.writeHead(true);
}), createErrorMessage(1));
}), createErrorMessage(true));
break;
case 9:
assert.throws(common.mustCall(() => {
res.writeHead([]);
}), createErrorMessage(0));
}), createErrorMessage([]));
break;
case 10:
assert.throws(common.mustCall(() => {
res.writeHead('this is not valid');
}), createErrorMessage(0));
}), createErrorMessage('this is not valid'));
break;
case 11:
assert.throws(common.mustCall(() => {
res.writeHead('404 this is not valid either');
}), createErrorMessage(0));
}), createErrorMessage('404 this is not valid either'));
break;
case 12:
assert.throws(common.mustCall(() => {
res.writeHead();
}), createErrorMessage(0));
}), createErrorMessage(undefined));
this.close();
break;
default:
Expand Down