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

http: subclass of Agent can override the initialization #11577

Closed
wants to merge 1 commit into from

Conversation

fengmk2
Copy link
Contributor

@fengmk2 fengmk2 commented Feb 27, 2017

Make userland's Agent inherit from http.Agent more easily.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Feb 27, 2017
@fengmk2
Copy link
Contributor Author

fengmk2 commented Feb 27, 2017

Just move "free" listener into "init()" method.
And replace var to let and const.

Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

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

The changes to use this instead of self, let/const instead of var, etc. don't look related to making Agent subclassable, nor are they justified from a performance standpoint. Besides the unrelated changes, the factoring-out of init() also looks ad-hoc to the specific usage of DestroyAgent, though I'll defer to the judgement of @nodejs/http on this.

@fengmk2
Copy link
Contributor Author

fengmk2 commented Feb 27, 2017

@TimothyGu revert all replacement.

@fengmk2
Copy link
Contributor Author

fengmk2 commented Feb 27, 2017

https://github.com/request/tunnel-agent/blob/master/index.js#L47 Now TunnelingAgent can inherits from http.Agent more easily.

function TunnelingAgent extends http.Agent {
  constructor(options = {}) {
    super(options);

    this.proxyOptions = this.options.proxy || {}
    this.maxSockets = this.options.maxSockets || http.Agent.defaultMaxSockets
  }

  init() {
    this.on('free', function onFree(socket, host, port) {
      // override the free socket listen
    });
   }
  
  // others methods
  addRequest() {}
}

@TimothyGu TimothyGu dismissed their stale review February 27, 2017 10:44

oudated review

@joyeecheung
Copy link
Member

ping @nodejs/http

@lpinca
Copy link
Member

lpinca commented May 27, 2017

@fengmk2 is this superseded by #11567?

@joyeecheung
Copy link
Member

@lpinca I don't think so, #11567 relaxed the constraint of extended agents, this PR makes the initialization part of the agents customizable via the init() method. Although the ongoing #13005 also tries to make HTTP agents more overridable as well.

This needs a rebase before anyone familiar with this part of the codebase can give a review...@fengmk2

@fengmk2 fengmk2 force-pushed the refactor-agent-constructor branch from 639c54f to 7d8575b Compare May 31, 2017 02:02
@fengmk2
Copy link
Contributor Author

fengmk2 commented May 31, 2017

@joyeecheung :)

I fixed the conflicts and push again. Anyone can review now!

Make userland's Agent inherit from http.Agent more easily.
@fengmk2 fengmk2 force-pushed the refactor-agent-constructor branch from 7d8575b to a3b1e98 Compare May 31, 2017 02:06
@BridgeAR
Copy link
Member

PTAL @nodejs/collaborators @nodejs/http

@jasnell
Copy link
Member

jasnell commented Aug 29, 2017

oy! completely missed this one, sorry @fengmk2

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Aug 29, 2017
@jasnell
Copy link
Member

jasnell commented Aug 29, 2017

This likely needs a doc update. Code looks fine on first read through, needs a CI

@jasnell
Copy link
Member

jasnell commented Aug 29, 2017

@jasnell jasnell requested a review from mscdex August 29, 2017 04:09
@fengmk2
Copy link
Contributor Author

fengmk2 commented Sep 6, 2017

@jasnell The ci is still running for a long time.

@jasnell
Copy link
Member

jasnell commented Sep 6, 2017

the ci completed, the results just are not posting appropriately back to Github.
Here's a fresh run: https://ci.nodejs.org/job/node-test-pull-request/9966/

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Can you please explain why you need sidestep the internal 'free' event handler? That part is critical for the logic of http.Agent. What is your use case? Maybe we are missing another event or method.

I am -1 with this change.

@BridgeAR
Copy link
Member

Ping @fengmk2

@BridgeAR
Copy link
Member

@fengmk2 do you still want to pursue this?

@BridgeAR
Copy link
Member

BridgeAR commented Oct 2, 2017

I am closing this due to long inactivity. @fengmk2 if you would like to pursue this, please reopen.

@BridgeAR BridgeAR closed this Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants