Skip to content

Conversation

@jonathanfoster
Copy link
Contributor

This PR resolves the issue when setting proxy config from env vars, the proxy config protocol is not set based on the env var URL. This causes all proxy server connections to use HTTP and results in invalid request errors.

If you set HTTPS_PROXY to an HTTPS URL...

export HTTPS_PROXY=https://localhost:8080

then the proxy config will be set without protocol, which is used later on to initiate the proxy connection.

proxy: {
  host: 'localhost'
  port: 8080
}

The proxy config should include protocol when parsing from env vars.

proxy: {
  host: 'localhost'
  port: 8080,
  protocol: 'https'
}

To reproduce this issue, create a local HTTPS proxy with mitmproxy and set HTTPS_PROXY to https://localhost:8080. mitmproxy will respond with a 400 and the error message HTTP protocol error in client request: Invalid request scheme: https.

@jonathanfoster
Copy link
Contributor Author

I just realized this PR is a dupe of #2562. I would still pull this one in though since it includes unit tests.

@jsevedge
Copy link

jsevedge commented Sep 2, 2020

+1, @jonathanfoster was just considering creating PR myself until I came across yours. Adding protocol supports will provide parity with deprecated requests project. Any idea when this will be merged?

@jonathanfoster
Copy link
Contributor Author

Looks like @chinesedfan removed the work in progress label a few days ago. I’m not sure what the workflow is like, but this makes me think it won’t make it into the next release.

@chinesedfan or @jasonsaayman, can you guys provide an update? Anything else we need to do to ship this PR?

@jasonsaayman
Copy link
Member

Hi @jonathanfoster

I think it will make it into the next release, I am starting to collect pull requests for 0.21 should get here soon.

Thanks

@jonathanfoster
Copy link
Contributor Author

@jasonsaayman Looks like this one didn't make it into 0.21. Anything I can do to help get it in 0.22? This PR fixes a huge pain point for anyone using axios behind a corporate proxy.

@jasonsaayman jasonsaayman added this to the v0.21.1 milestone Nov 19, 2020
Copy link
Member

@jasonsaayman jasonsaayman left a comment

Choose a reason for hiding this comment

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

This looks good to me, has tests, and does not seem to break backward compatibility.

@jasonsaayman
Copy link
Member

@chinesedfan can you have a look let me know if we can merge?

Copy link
Contributor

@chinesedfan chinesedfan left a comment

Choose a reason for hiding this comment

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

Looks good to me, except for a few suggestions.

@chutchi2
Copy link

chutchi2 commented Dec 1, 2020

It looks like all the requested changes have been completed @chinesedfan. Bumping this thread as a follow up.

This was referenced Mar 18, 2021
mbargiel pushed a commit to mbargiel/axios that referenced this pull request Jan 27, 2022
* Fixing proxy protocol config when parsed from env vars

* Adding instructions to specify proxy protocol when setting proxy config

* Moved HTTPS proxy config instruction closer to example

* Clear https_proxy env var so as to not impact other tests
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

Successfully merging this pull request may close these issues.

5 participants