elixir-tesla / tesla

The flexible HTTP client library for Elixir, with support for middleware and multiple adapters.
MIT License
2.01k stars 346 forks source link

Can't connect to anything with Gun adapter using HTTP proxy #552

Open howaboutlollmao opened 1 year ago

howaboutlollmao commented 1 year ago

Tesla and Gun both with latest commits from master branch, but the same can be seen with Tesla 1.4.4 and Gun 2.0.0-rc1.

gun_client = Tesla.client([], Tesla.Adapter.Gun)
Tesla.get(gun_client, "http://icanhazip.com", opts: [adapter: [timeout: 3_000, proxy: {{127, 0, 0, 1}, 8118}]])

Running this in IEX returns {:error, :recv_response_timeout} no matter what the URL is. SOCKS proxies work fine, the problem is only with HTTP. https://github.com/ninenines/gun/issues/300 might be related, since the symptoms are similar (connection is created, but no request to end server is made).

tanguilp commented 4 months ago

Not a solution to your problem, but you can use httpc instead from Tesla v1.11:

def get_adapter(uri) do
  profile = uri |> to_string() |> String.to_atom()
  {:ok, _pid} = :inets.start(:httpc, profile: profile)
  :httpc.set_options([https_proxy: {{to_charlist(uri.host), uri.port}, []}], profile)
  {Tesla.Adapter.Httpc, profile: profile}
end