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 feature not work #326

Closed
sv158 opened this issue Jan 14, 2021 · 3 comments
Closed

proxy feature not work #326

sv158 opened this issue Jan 14, 2021 · 3 comments

Comments

@sv158
Copy link

sv158 commented Jan 14, 2021

Expected behaviour

The node client should get the http_proxy or https_proxy environment variables and send request via proxy config.

Actual behaviour

The node client did not use proxy anyway.

In current version of this client, I can not find related implement like tldr-pages/tldr#72 . Is that mean the proxy detect feature has been remove for long time ago?

Environment

  • Operating system - Ubuntu 20.04
  • NodeJS version - v14.15
@bl-ue
Copy link
Contributor

bl-ue commented Jan 14, 2021

@v3470 I'm unable to reproduce any issue. The node.js client uses the https_proxy environment variable, and not the http_proxy.

I'm using Charles (on macOS 11.1) for a quick proxy, and when I set https_proxy in my terminal and run tldr -u it works:

$ export https_proxy="https://127.0.0.1:8888"
$ tldr -u
✔ Updating...
✔ Creating index...
$

Can you share more details, such as the following?

  • OS version
  • node version
  • npm version
  • *_proxy environment variables for your terminal session
  • the commands you're running

@bl-ue
Copy link
Contributor

bl-ue commented Jan 14, 2021

In current version of this client, I can not find related implement like tldr-pages/tldr#72 . Is that mean the proxy detect feature has been remove for long time ago?

@v3470 the Node.js client currently uses a very popular HTTP client called axios, which handles proxy configuration automatically. In case you're interested, support for the http_proxy and https_proxy environment variables was added to axios back in 2016 with axios/axios#366.

@sv158
Copy link
Author

sv158 commented Jan 16, 2021

@bl-ue I tested again on a different virtual machine, and this time I'm almost sure that it's the axios part's problem.

First I config the proxy env variable with export http_proxy=http://192.168.1.9:7890

Then I tested it with curl http://google.com and successfully got http 302 page(I used google.com because it has been banned by my ISP).

Next I tried to use axios to do the same thing in node cli, and got the result:

> ax({method:'get',url:'http://google.com',proxy:{protocol:'http',host:'192.168.1.2',port:7890}}).then(function(resp){console.log(resp)}).catch(function(err){console.log(err)});
Promise { <pending> }
> Error: connect ECONNREFUSED 127.0.0.1:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
    at TCPConnectWrap.callbackTrampoline (internal/async_hooks.js:129:14) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 80,
  config: {
    url: 'http://google.com',
    method: 'get',
    headers: {
      Accept: 'application/json, text/plain, */*',
      'User-Agent': 'axios/0.20.0'
    },
    proxy: { protocol: 'http', host: '192.168.1.2', port: 7890 },
    ...
  response: undefined,
  isAxiosError: true,
  ...
}

Also, if I use proxy env variable with axios and without explicit proxy config, then I'll get same result as above.

To test this without proxy, I also tried with ax({method:'get',url:'http://google.com',proxy:false}).then(function(resp){console.log(resp)}).catch(function(err){console.log(err)}); but this time I only got a pending promise, no error.

I don't know what's wrong with the axios exactly but now I knew that it's not the problem with tldr-node-client itself.

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