Skip to content

Commit

Permalink
fix: use mint passive mode (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis authored Sep 10, 2023
1 parent f80c97d commit 798e105
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/tesla/adapter/mint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ if Code.ensure_loaded?(Mint.HTTP) do
_ -> opts
end

opts = Map.put_new(opts, :mode, :passive)

with {:ok, conn} <-
HTTP.connect(String.to_atom(uri.scheme), uri.host, uri.port, Enum.into(opts, [])) do
# If there were redirects, and passed `closed_conn: false`, we need to close opened connections to these intermediate hosts.
Expand Down
8 changes: 4 additions & 4 deletions test/tesla/adapter/mint_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ defmodule Tesla.Adapter.MintTest do
assert byte_size(response.body) == 16
end

describe "mode: :passive" do
describe "mode: :active" do
test "body_as: :plain" do
request = %Env{
method: :get,
url: "#{@http}/stream-bytes/10"
}

assert {:ok, %Env{} = response} = call(request, mode: :passive)
assert {:ok, %Env{} = response} = call(request, mode: :active)
assert response.status == 200
assert byte_size(response.body) == 16
end
Expand All @@ -98,7 +98,7 @@ defmodule Tesla.Adapter.MintTest do
url: "#{@http}/stream-bytes/10"
}

assert {:ok, %Env{} = response} = call(request, body_as: :stream, mode: :passive)
assert {:ok, %Env{} = response} = call(request, body_as: :stream, mode: :active)
assert response.status == 200
assert Enum.join(response.body) |> byte_size() == 16
end
Expand All @@ -109,7 +109,7 @@ defmodule Tesla.Adapter.MintTest do
url: "#{@http}/stream-bytes/10"
}

assert {:ok, %Env{} = response} = call(request, body_as: :chunks, mode: :passive)
assert {:ok, %Env{} = response} = call(request, body_as: :chunks, mode: :active)
assert response.status == 200
%{conn: conn, ref: ref, opts: opts, body: body} = response.body

Expand Down

0 comments on commit 798e105

Please sign in to comment.