Skip to content

Commit

Permalink
fix: proxy events into instance var and add test script (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
akoserwal authored and DonutEspresso committed May 24, 2018
1 parent fa53274 commit de72f49
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/server.js
Expand Up @@ -34,14 +34,6 @@ patchRequest(http.IncomingMessage);
///--- Globals

var sprintf = util.format;
var PROXY_EVENTS = [
'clientError',
'close',
'connection',
'error',
'listening',
'secureConnection'
];

///--- API

Expand Down Expand Up @@ -138,6 +130,14 @@ function Server(options) {
var fmt = mergeFormatters(options.formatters);
this.acceptable = fmt.acceptable;
this.formatters = fmt.formatters;
this.proxyEvents = [
'clientError',
'close',
'connection',
'error',
'listening',
'secureConnection'
];

if (options.spdy) {
this.spdy = true;
Expand Down Expand Up @@ -187,10 +187,10 @@ function Server(options) {

this.router.on('mount', this.emit.bind(this, 'mount'));

if (!options.handleUpgrades && PROXY_EVENTS.indexOf('upgrade') === -1) {
PROXY_EVENTS.push('upgrade');
if (!options.handleUpgrades) {
this.proxyEvents.push('upgrade');
}
PROXY_EVENTS.forEach(function forEach(e) {
this.proxyEvents.forEach(function forEach(e) {
self.server.on(e, self.emit.bind(self, e));
});

Expand Down
16 changes: 16 additions & 0 deletions test/server.test.js
Expand Up @@ -2430,3 +2430,19 @@ test('should emit error with multiple next calls with strictNext', function(t) {
});
});
});

test('should have proxy event handlers as instance', function(t) {
var server = restify.createServer({
handleUpgrades: false
});
t.equal(server.proxyEvents.length, 7);

server = restify.createServer({
handleUpgrades: true
});

t.equal(server.proxyEvents.length, 6);
server.close(function() {
t.end();
});
});

0 comments on commit de72f49

Please sign in to comment.