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

Proxy support #79

Closed
sindresorhus opened this issue Jul 6, 2015 · 23 comments · Fixed by #82
Closed

Proxy support #79

sindresorhus opened this issue Jul 6, 2015 · 23 comments · Fixed by #82
Labels
enhancement This change will extend Got features

Comments

@sindresorhus
Copy link
Owner

sindresorhus commented Jul 6, 2015

Previous issue #7. I couldn't care less about this, but it's useful to have a place to refer people that open issues elsewhere.

A good PR would be accepted, but won't happen from my part.

I would prefer for the solution to be an external module got can just depend on as I don't want to have to maintain it. Maybe https://github.com/mikeal/tunnel-agent.

I strongly believe this is something that should be a part of Node.js and not every module doing HTTP. +1 this issue if you agree: nodejs/node#8381

@kevva
Copy link
Contributor

kevva commented Jul 7, 2015

I created a module for this, but didn't get the tests passing IIRC. I'll try finishing it asap.

@floatdrop floatdrop mentioned this issue Jul 15, 2015
@sindresorhus sindresorhus reopened this Jul 23, 2015
@Flet
Copy link

Flet commented Jul 29, 2015

I've run into two great packages now that use got, but with no proxy support I can't use them :(

@kevva is there anything I can do to help with your module?

@floatdrop
Copy link
Contributor

@Flet caw it is, I guess.

@kevva
Copy link
Contributor

kevva commented Jul 31, 2015

Yup, haven't been able to check if it's working correctly though.

@alexpaluzzi
Copy link

Is not working (as mentioned in other issue).

Several companies don't have an actual "proxy" but rather, an HTTPS inspection point somewhere down the line. (Like, in my case, "Check Point Firewall"). This requires some self-signed certs to work and it definitely causes some issues by default with npm and other package managers.

npm is easily solved with "strict-ssl=false". Curl has a flag for it as well.

download worked great before whatever tweaks were made a few weeks ago. @kevva's fix probably did help those that have "real" proxies.

I'm not a network admin, so I'm probably messing some of this lingo up. I did speak with my network guys here, though, and after a few days of research, this is where we landed. Hopefully this helps somehow.

@kevva
Copy link
Contributor

kevva commented Aug 3, 2015

If you look at https://github.com/koichik/node-tunnel, do you see something there that might fix it?

@alexpaluzzi
Copy link

I immediately had the same thought after I saw your caw. Unfortunately, I don't see anything there. If I have some time, I'm going to look at npm and what exactly strict-ssl is doing. Even without an actual proxy, that config is the difference between working and not working.

@alexpaluzzi
Copy link

@sindresorhus Tears of joy here.

http doesn't have a way to handle these certificates. request does, of course (with agentOptions and strictSsl). I found a couple ancient issues from 2013 asking for a strict-ssl option. I don't see one yet.

The workaround for http is setting this environment variable (not my favorite solution, but it's the only one I've found):
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

I think your tunnel-agent is working good for traditional proxies. I wager this can be closed now. I'm certain there were people having my exact issue here, so hopefully this will help.

@stevenvachon
Copy link
Contributor

Progress?

@sindresorhus
Copy link
Owner Author

@stevenvachon#159 (comment)

xzyfer added a commit to xzyfer/node-sass that referenced this issue Apr 21, 2016
This reverts commit c2d24c2.

Unfortunately got does not have good [proxy support][1] which
was missed during review.

[1]: sindresorhus/got#79
xzyfer added a commit to xzyfer/node-sass that referenced this issue Apr 21, 2016
This reverts commit c2d24c2.

Unfortunately got does not have good [proxy support][1] which
was missed during review.

Fixes sass#1458

[1]: sindresorhus/got#79
xzyfer added a commit to sass/node-sass that referenced this issue Apr 21, 2016
This reverts commit c2d24c2.

Unfortunately got does not have good [proxy support][1] which
was missed during review.

Fixes #1458

[1]: sindresorhus/got#79
@sindresorhus
Copy link
Owner Author

New thread about adding proxy support to Node.js core: nodejs/node#8381 (Vote/comment please)

@tjwebb
Copy link

tjwebb commented Dec 5, 2016

fwiw, the node yeoman generator is also experiencing this issue: trailsjs/generator-node#1.

Is there a patch available?

@chocolateboy
Copy link

Until this is fixed in Node, a workaround for Linux/BSD/macOS is to use proxychains-ng.

You'll need your proxy server's IP address and port:

$ echo $http_proxy
http://proxy.example.com:8080/

$ ping proxy.example.com
PING proxy.example.com (192.0.2.42) 56(84) bytes of data.

- which should be added to the end of /etc/proxychains.conf (comment out the default rule) e.g.:

# socks4 127.0.0.1 9050
http 192.0.2.42 8080

Then you're all set:

$ proxychains -q npm-check    
Checking for unused packages...

$ alias npm-name="proxychains -q npm-name"
$ npm-name proxychains-ng-rocks
✔ proxychains-ng-rocks is available

@stevenvachon
Copy link
Contributor

What do you guys think of https://github.com/stevenvachon/auto-tunnel before I publish?

@kevva
Copy link
Contributor

kevva commented May 30, 2017

Is there any differences from https://github.com/kevva/caw? Could really use a PR if you notice anything that can be improved upon.

@paambaati
Copy link

@kevva I can see that @stevenvachon's auto-tunnel is very similar to caw.

@silverwind
Copy link

auto-tunnel looks promising. From a quick look, it seems to supports NO_PROXY which I think caw does not. I'd suggest to clean up the code and push a 1.0.0 and open a PR here.

@rightaway
Copy link

What's the recommended way to use got with HTTPS/SOCKS5 proxies?

@stevenvachon
Copy link
Contributor

stevenvachon commented Nov 1, 2017

auto-tunnel wasn't released because:

buschtoens added a commit to buschtoens/node-cloudflare that referenced this issue Dec 22, 2017
This allows the user to pass optional options through to the `got` instance. For instance, users can now connect via proxies.

Here is an example using [`caw`](https://github.com/kevva/caw), as further described in [sindresorhus/got#435](sindresorhus/got#435 (comment)) and originally brought up in [sindresorhus/got#79](sindresorhus/got#79).

```js
import Cloudflare from 'cloudflare':
import caw from 'caw';

const cf = new Cloudflare({
  email: '[email protected]',
  key: '<your API key here>',
  gotOptions: {
    agent: caw({ protocol: 'https' }) // Cloudflare API is HTTPS only
  }
});
```
@wildone
Copy link

wildone commented Apr 25, 2018

NPM works fine with --https-proxy and --proxy, so its only logical that all modules built on top of it support this basic mechanism. I had a situation using npm with proxy where another module was using your module to build its depenedecies... well that did not work at all. I ended up fixing the issue with a workaround.

So maybe this needs a another look as "A nicer interface to the built-in http module" (from your readme) is a big call if basic http modules functions are not replicated... thats just my 2cents

@sindresorhus
Copy link
Owner Author

NPM works fine with --https-proxy and --proxy, so its only logical that all modules built on top of it support this basic mechanism.

Got is not built on top of npm.

So maybe this needs a another look as "A nicer interface to the built-in http module" (from your readme) is a big call if basic http modules functions are not replicated...

The Node.js core http API doesn't support proxies built-in either.

@sindresorhus
Copy link
Owner Author

Closing this as I don't see us adding native proxy support. It's just too complicated and would bloat Got. It can already be done by the user by following this recipe.

Repository owner locked as resolved and limited conversation to collaborators Sep 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement This change will extend Got features
Projects
None yet
Development

Successfully merging a pull request may close this issue.