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

Allow passing custom HTTP Agent #14

Closed
bitinn opened this issue Apr 9, 2016 · 5 comments
Closed

Allow passing custom HTTP Agent #14

bitinn opened this issue Apr 9, 2016 · 5 comments

Comments

@bitinn
Copy link
Contributor

bitinn commented Apr 9, 2016

This enables passing custom agent when you can, say, proxy a request, or accept self-signed certificate.

The proxy options is especially useful to me because here in China, many website do require a bit of network tunneling to work...

I did try to make it happen on Node.js core, but I guess that's probably too large a change to push forward, allowing custom agent passing on userland code seems like the best solution to me.

Alternative, which require more efforts, would be to allow user to take over the request module, eg. can I implement the same interface using node-fetch instead of request?

But really as long as I can make a request to Twitter using my local tunnel, I am a happy man.

ref:

@simov
Copy link
Owner

simov commented Apr 9, 2016

Request accepts a custom agent through its agent option, so as long as you are using the Basic API you can pass that option to the underlying request module.

Let me know if that works for you.

@bitinn
Copy link
Contributor Author

bitinn commented Apr 9, 2016

OK that's good to know.

By the way, is it possible to do this?

        client.query()
            .get('account/verify_credentials', REQUEST_OPTIONS)
            .auth(opts.access_token, opts.access_secret)
            .request(function(err, res, body) {
            ...

@bitinn bitinn closed this as completed Apr 9, 2016
@simov
Copy link
Owner

simov commented Apr 9, 2016

Oh, you can actually use the options method:

client.query()
            .get('account/verify_credentials')
            .auth(opts.access_token, opts.access_secret)
            .options(REQUEST_OPTIONS)
            .request(function(err, res, body) {
            ...

Totally forgot about that.

As for this question:

Can I implement the same interface using node-fetch instead of request?

I'm working on a rewrite where the Purest's logic is extracted into modules that consume a common interface, so as long as you write a thin wrapper for your HTTP client of choice exposing the same interface, Purest will be able to use it.

@bitinn
Copy link
Contributor Author

bitinn commented Apr 9, 2016

Cool, and didn't know you were already working on the abstraction!

@simov
Copy link
Owner

simov commented Apr 9, 2016

Yes, it will be a major release because I'll probably break a few things, for the benefit of having more flexible solution :)

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

No branches or pull requests

2 participants