Skip to content
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
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
os:
- ubuntu-latest
node-version:
- 10.x
- 12.x
- 14.x
- 16.x
runs-on: ${{matrix.os}}
Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,7 @@ $ npm install restify

## Supported Node Versions

Restify aims to support the Node.js LTS (Active and Maintenance) versions along with Node.js current stable version.

| Node Release | Supported in Current Version | Notes |
| :--: | :---: | :---: |
| 11.x | **Yes** | Current stable |
| 10.x | **Yes** | Active LTS |
| 8.x | **Yes** | Maintenance LTS |
| 6.x | **No** | Use restify v7.x, team will backport critical issues only |
| 4.x | **No** | Use restify v7.x, team will backport critical issues only |
Restify currently works on Node.js v14.x and v16.x.

## License

Expand Down
2 changes: 1 addition & 1 deletion lib/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Chain.prototype.run = function run(req, res, done) {
var handler = self._stack[index++];

// all done or request closed
if (!handler || req.closed()) {
if (!handler || req.connectionState() === 'close') {
process.nextTick(function nextTick() {
return done(err, req, res);
});
Expand Down
5 changes: 4 additions & 1 deletion lib/plugins/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ function serveStatic(options) {
var re = new RegExp('^' + escapeRE(p) + '/?.*');

function serveFileFromStats(file, err, stats, isGzip, req, res, next) {
if (typeof req.closed === 'function' && req.closed()) {
if (
typeof req.connectionState === 'function' &&
req.connectionState() === 'close'
) {
next(false);
return;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

'use strict';

const { emitWarning } = require('node:process');
var url = require('url');
var sprintf = require('util').format;

Expand Down Expand Up @@ -846,6 +847,11 @@ function patch(Request) {
* @returns {Boolean} is closed
*/
Request.prototype.closed = function closed() {
emitWarning(
'restify req.closed is deprecated, will be removed on Restify 10',
'RestifyDeprecationWarning',
'RestifyDEPReqClosed'
);
var self = this;
return self.connectionState() === 'close';
};
Expand Down
50 changes: 25 additions & 25 deletions test/chain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ test('calls all the handlers', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand Down Expand Up @@ -58,8 +58,8 @@ test('abort with Error in next', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand All @@ -85,7 +85,7 @@ test('abort with false in next', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
connectionState: function() {
return false;
}
},
Expand All @@ -112,8 +112,8 @@ test('abort with closed request', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return closed;
connectionState: function() {
return closed ? 'close' : '';
}
},
{},
Expand Down Expand Up @@ -143,8 +143,8 @@ test('cals error middleware', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand All @@ -170,8 +170,8 @@ test('onceNext prevents double next calls', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand Down Expand Up @@ -208,8 +208,8 @@ test('throws error for double next calls in strictNext mode', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand All @@ -234,8 +234,8 @@ test('calls req.startHandlerTimer', function(t) {
t.done();
},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand All @@ -257,8 +257,8 @@ test('calls req.endHandlerTimer', function(t) {
t.equal(handleName, 'foo');
t.done();
},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand Down Expand Up @@ -299,8 +299,8 @@ test('waits async handlers', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand Down Expand Up @@ -329,8 +329,8 @@ test('abort with rejected promise', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand Down Expand Up @@ -359,8 +359,8 @@ test('abort with rejected promise without error', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
},
path: function() {
return '/';
Expand Down Expand Up @@ -395,8 +395,8 @@ test('abort with throw inside async function', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand Down
8 changes: 4 additions & 4 deletions test/chainComposer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ test('chainComposer creates a valid chain for a handler array ', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand All @@ -53,8 +53,8 @@ test('chainComposer creates a valid chain for a single handler', function(t) {
{
startHandlerTimer: function() {},
endHandlerTimer: function() {},
closed: function() {
return false;
connectionState: function() {
return '';
}
},
{},
Expand Down
24 changes: 24 additions & 0 deletions test/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,27 @@ test('should emit restifyDone event when request is fully served with error', fu
clientDone = true;
});
});

test('should emit warning if closed is called', function(t) {
let warningCalled = false;
SERVER.get('/ping/:name', function(req, res, next) {
function testWarning(warning) {
t.equal(warning.name, 'RestifyDeprecationWarning');
t.equal(warning.code, 'RestifyDEPReqClosed');
t.ok(warning.stack);
warningCalled = true;

res.send('ok');
return next();
}
process.once('warning', testWarning);
t.notOk(req.closed());
});

CLIENT.get('/ping/lagavulin', function(err, _, res) {
t.ifError(err);
t.equal(res.statusCode, 200);
t.ok(warningCalled);
t.end();
});
});
4 changes: 2 additions & 2 deletions test/router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var helper = require('./lib/helper.js');
var test = helper.test;
var mockReq = {
params: {},
closed: function() {
return false;
connectionState: function() {
return '';
},
startHandlerTimer: function() {},
endHandlerTimer: function() {}
Expand Down