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 event local variable #1655

Closed
wants to merge 4 commits into from

Conversation

akoserwal
Copy link
Contributor

@akoserwal akoserwal commented May 7, 2018

Pre-Submission Checklist

  • [ X] Opened an issue discussing these changes before opening the PR
  • [ X] Ran the linter and tests via make prepush
  • 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.

I haven't added unit-test. As this is my first PR. I like to get initial review. before working on the unit test.

Changes

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

@DonutEspresso
Copy link
Member

Hi @akoserwal, thanks for your first time PR! 🎉 🎉

This approach LGTM! Any concerns @hekike?

lib/server.js Outdated
@@ -138,6 +130,12 @@ function Server(options) {
var fmt = mergeFormatters(options.formatters);
this.acceptable = fmt.acceptable;
this.formatters = fmt.formatters;
this.proxyEvents = new Array('clientError',
Copy link
Member

Choose a reason for hiding this comment

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

Please use the shorthand syntax: new Array() => []

@@ -187,10 +185,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.

Please use includes()

Copy link
Member

Choose a reason for hiding this comment

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

@akoserwal now that proxyEvents in retrospect I don't think we even need the indexOf check - is that right?

@hekike
Copy link
Member

hekike commented May 14, 2018

Yep, looks good to me.

@akoserwal
Copy link
Contributor Author

@hekike : done

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.includes === false) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you mean this.proxyEvents.includes('upgrade') === false? That said, I don't think node 4 supports the includes method. @hekike we may have to stick with indexOf here for now?

Copy link
Member

Choose a reason for hiding this comment

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

You are right, apologize for extra work :/

@DonutEspresso
Copy link
Member

Hi @akoserwal - thanks for the contribution! Would you mind adding unit tests to round out the PR?

@akoserwal
Copy link
Contributor Author

@DonutEspresso: Please can you review again. I did make check-style locally before pushing. it shows clean. Checks failed due it

@DonutEspresso
Copy link
Member

@hekike did we setup the make file to run prettier? What's the best way to autofix that stuff?

handleUpgrades: true
});

t.equal(server.proxyEvents.length,6);
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)

@akoserwal akoserwal closed this May 16, 2018
@akoserwal akoserwal deleted the fix-global-proxy-events branch May 16, 2018 18:54
@akoserwal
Copy link
Contributor Author

please review #1661: @DonutEspresso @hekike

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

3 participants