Skip to content

Commit

Permalink
Avoid failing when req.setTimeout is called.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Dec 29, 2016
1 parent 80994d9 commit bb18a4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/unexpectedExpress.js
Expand Up @@ -226,6 +226,10 @@ module.exports = {
req.push(null);
}

// Make req.connection.setTimeout a no-op so that req.setTimeout doesn't break
// in this mocked state:
req.connection.setTimeout = function () {};

req.httpVersion = httpRequest.protocolVersion;
var matchProtocolVersion = String(httpRequest.protocolVersion).match(/^(\d+)(?:\.(\d+))$/);
if (matchProtocolVersion) {
Expand Down Expand Up @@ -261,7 +265,6 @@ module.exports = {
rawResponseChunks.push(chunk);
cb();
};

var isAsync = false,
isDestroyed = false,
requestDestroyed = false,
Expand Down
10 changes: 10 additions & 0 deletions test/unexpectedExpress.js
Expand Up @@ -123,6 +123,16 @@ describe('unexpectedExpress', function () {
}), 'to yield exchange satisfying', {response: 404});
});

it('should not break when req.setTimeout is called', function () {
return expect(express().use(function (req, res, next) {
req.setTimeout(10);
res.status(200).end();
}), 'to yield exchange satisfying', {
request: 'GET /',
response: 200
});
});

it('should allow overriding the HTTP version', function () {
return expect(express().use(function (req, res, next) {
expect(req.httpVersion, 'to equal', '2.0');
Expand Down

0 comments on commit bb18a4d

Please sign in to comment.