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: proxy events into instance var and add test script #1661

Merged
merged 2 commits into from May 24, 2018

Conversation

akoserwal
Copy link
Contributor

Pre-Submission Checklist

  • [ x] Opened an issue discussing these changes before opening the PR
  • [ x] Ran the linter and tests via make prepush
  • [ x] Included comprehensive and convincing tests for changes

Issues

#1348
Closes:

Summarize the issues that discussed these changes
Since PROXY_EVENTS are shared between every instance of a restify server, and upgrade is added but never removed, all future instances of Server will have the upgrade event proxied.

Changes

What does this PR do?
update PROXY_EVENTS to an instance variable.

@akoserwal
Copy link
Contributor Author

@DonutEspresso, @hekike : I created a new branch. Instead of rebase my previous branch. I accidentally clicked over update branch on the github uI. Which will add non-essential commits. I will take care from next time.

@akoserwal akoserwal mentioned this pull request May 20, 2018
1 task
@DonutEspresso
Copy link
Member

DonutEspresso commented May 22, 2018

Thanks @akoserwal! Apologies for the trouble. I left some minor comments I copied over from the last PR- let me know if they make sense!

var server = restify.createServer({
handleUpgrades: false
});
t.equal(server.proxyEvents.length, 7);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I expect handleUpgrades: true to be 7, and 6 for false (may be related to the && indexOf check above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the doc

options.handleUpgrades Boolean Hook the upgrade event from the node HTTP server, pushing Connection: Upgrade requests through the regular request handling chain. (optional, default false) (http://restify.com/docs/server-api/).

We are updating proxyEvents array when
options.handleUpgrades:false
size will be 7 and in-case of true. we will skip it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I can't read. Must have been a long day. :D

lib/server.js Outdated
@@ -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.indexOf('upgrade') === -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that proxyEvents is specific to the instance of the server being created, I don't think we even need the indexOf check right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DonutEspresso: right, I can remove it.

var server = restify.createServer({
handleUpgrades: false
});
t.equal(server.proxyEvents.length, 7);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I can't read. Must have been a long day. :D

@DonutEspresso
Copy link
Member

@akoserwal thank you for the contribution! 🎉

@DonutEspresso DonutEspresso merged commit de72f49 into restify:master May 24, 2018
@akoserwal
Copy link
Contributor Author

@DonutEspresso : Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants