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

Gun adapter proxy auths #424

Merged
merged 6 commits into from
Dec 7, 2020

Conversation

matijavibe
Copy link
Contributor

This PR aims to address the lack of ability to use Basic auth when using proxy (regular or Socks) via GUN adapter.
Also a pattern match is added to not force TLS in case proxy is used, and leave it to GUN to use TLS if the proxy port is 443, otherwise TCP will be used.
The combination of TLS and a port other than 443 for proxy can be accomplished by passing the transport option when creating the Tesla Client and adding it as Adapter opt.

@teamon
Copy link
Member

teamon commented Oct 12, 2020

@alex-strizhakov 👀 🙏

@teamon
Copy link
Member

teamon commented Nov 6, 2020

@alex-strizhakov Could you take a look at this PR?

Copy link
Contributor

@alex-strizhakov alex-strizhakov left a comment

Choose a reason for hiding this comment

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

the rest looks good 👍

@@ -38,6 +38,8 @@ if Code.ensure_loaded?(:gun) do
- `:close_conn` - Close connection or not after receiving full response body. Is used for reusing gun connections. Defaults to `true`.
- `:certificates_verification` - Add SSL certificates verification. [erlang-certifi](https://github.com/certifi/erlang-certifi) [ssl_verify_fun.erl](https://github.com/deadtrickster/ssl_verify_fun.erl)
- `:proxy` - Proxy for requests. **Socks proxy are supported only for gun master branch**. Examples: `{'localhost', 1234}`, `{{127, 0, 0, 1}, 1234}`, `{:socks5, 'localhost', 1234}`.
NOTE: By default GUN uses TLS as transport if the specified port is 443, if TLS is required for proxy conection on another port please specify transport using the Gun options below otherwise tcp will be used
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
NOTE: By default GUN uses TLS as transport if the specified port is 443, if TLS is required for proxy conection on another port please specify transport using the Gun options below otherwise tcp will be used
NOTE: By default GUN uses TLS as transport if the specified port is 443, if TLS is required for proxy connection on another port please specify transport using the Gun options below otherwise tcp will be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, corrected :)

@@ -345,6 +366,18 @@ if Code.ensure_loaded?(:gun) do

defp tunnel_tls_opts(opts, _, _), do: opts

defp add_proxy_auth_credentials(opts, %{proxy_auth: {username, password}})
when not is_nil(username) and not is_nil(password),
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe is_binary/1 guard will be more suitable here for checking username and password?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are absolutely right, corrected.

@teamon teamon merged commit 586c543 into elixir-tesla:master Dec 7, 2020
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.

3 participants