axios: Axios Proxy Issues - 501 and SSL errors

Describe the bug

Getting weird error messages when passing a proxy into an Axios request. I’ve tried to add a proxy parameter to the following GET request and I get a 501 error code and when I then add a protocol parameter to the proxy object I get an openssl error

Note that I don’t have any of these issues when using the library axios-https-proxy-fix, https://www.npmjs.com/package/axios-https-proxy-fix

To Reproduce

axios
    .get(prod, {
        proxy: {
            host: proxy.host,
            port: proxy.port,
            auth: {
                username: proxy.userName,
                password: proxy.password,
            },
        }
    })

Then I tried adding protocol to the proxy object, like so:

axios
    .get(prod, {
        proxy: {
            protocol: "https",
            host: proxy.host,
            port: proxy.port,
            auth: {
                username: proxy.userName,
                password: proxy.password,
            },
        }
    })

Error:

write EPROTO 17828:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:

Expected behavior

No 501 and no openssl issues. Should get a 200 response.

Environment

  • Axios Version 0.21.0
  • Node.js Version 12.17
  • OS: Windows 10

Additional context/Screenshots

N/A

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 32
  • Comments: 20 (1 by maintainers)

Most upvoted comments

Until a proper fix is implemented in the library, here is the workaround I used:

import HttpsProxyAgent from 'https-proxy-agent'
    this.client = axios.create({
      baseURL: `https://${this.host}`,
      httpsAgent: new HttpsProxyAgent(process.env.HTTPS_PROXY),
      proxy: false,
      ....
    });

Note that proxy must be set to false otherwise the adapter will try to initialize it again from the environment variable.

For a complete example (with proxy and no proxy): https://github.com/spectrocloud/k8s-set-context/blob/690044f1c02048af0e4b7470dd70306ef1f4556b/src/client.ts#L36-L54

Not working for me either, please fix

Having the same issue. Could we implement the fix of this fixer library/package, axios-https-proxy-fix, it also fixed my issue. Cheers.

I’m facing the same issue

this keep happening and @saamalik solution did not work for me. is there a working workaround or should we downgrade to 0.18 in the mean time ?

I tried with different proxies and I can confirm none of mine are working either

Having this weird issue myself

You can add this parameter to start: node --tls-min-v1.0 xxx.js

For version “0.26.0” @saamalik snippet works using @HandsomeTea flag, for the ones that can not control the CLI flags, you can use also an environment variable:

NODE_OPTIONS=--tls-min-v1.0

To create the proxy instance I used:

    const proxyAgent = new HttpsProxyAgent('http://username:password@proxy_uri:port');

Reference: https://matthewdf10.medium.com/aws-lambda-node-12-x-with-tls-1-0-b8c33644ea58

Same issue