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

Cannot get proxy to work with Tesla adapter #148

Closed
glappen opened this issue May 19, 2022 · 5 comments · Fixed by #186
Closed

Cannot get proxy to work with Tesla adapter #148

glappen opened this issue May 19, 2022 · 5 comments · Fixed by #186

Comments

@glappen
Copy link

glappen commented May 19, 2022

Hello,

I am trying out this plug, and ran into a strange issue. Configuring tesla_client option was also kind of tricky, and I don't know if I have it setup correctly. The problem I see is that when configured with Tesla (using either mint or hackney as tesla_client), the requests just hang and never complete. Using hackney directly instead of tesla seems to work.

Here's how I have it setup:

mix.exs:

defp deps do
  [
    {:reverse_proxy_plug, "~> 2.1"},
    {:tesla, "~> 1.4"},
    {:mint, "~> 1.4"},
    {:castore, "~> 0.1"}
  ]
end

endpoint.ex:

defmodule MiddleMan.Endpoint do
  use Plug.Router

  plug(Plug.Telemetry, event_prefix: [:middle_man, :plug])
  plug(Plug.Logger)
  plug(:match)

  plug(:dispatch)

  get "/hello" do
    send_resp(conn, 200, "world")
  end

forward("/test",
    to: ReverseProxyPlug,
    client: ReverseProxyPlug.HTTPClient.Adapters.Tesla,
    upstream: "//localhost:8000/",
    client_options: [
      tesla_client: Tesla.client([], {Tesla.Adapter.Mint, []})
    ]
  )
end

When I make a request to http://localhost:4000/test/test.json, I see this in the logs:
15:21:59.484 [info] GET /test/test.json
and the browser keeps loading and loading with no response.

Any clues what I did wrong above? I was unable to figure out how to pass tesla_client option in config.exs, so I ended up passing the options in the forward call.

Any help would be appreciated.....thanks for your time!

@akasprzok
Copy link

I've got the same issue.

@akasprzok
Copy link

Looking into the code, there's no handling for response_mode: :stream if using Tesla.

@mwhitworth
Copy link
Collaborator

According to elixir-tesla/tesla#271 and the Stream section of the documentation, streaming responses isn't supported.

But the current behaviour isn't ideal - we should fail much earlier than that if we can detect this. I'll see what can be done here.

@mwhitworth
Copy link
Collaborator

It now throws an ArgumentError if the adapter and response mode are incompatible.

Point taken about the configuration; I'd like to make a pass at the README.md and provide some more examples too.

@mwhitworth
Copy link
Collaborator

Released in v2.4.0

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 a pull request may close this issue.

3 participants