From 634ab98fadd3a9e7d2dff63d6c38f47caa1292a2 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Lazo Date: Mon, 15 May 2023 13:37:10 -0400 Subject: [PATCH] fix: use mint passive mode --- lib/tesla/adapter/mint.ex | 2 ++ test/tesla/adapter/mint_test.exs | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/tesla/adapter/mint.ex b/lib/tesla/adapter/mint.ex index c88057fb..958964a1 100644 --- a/lib/tesla/adapter/mint.ex +++ b/lib/tesla/adapter/mint.ex @@ -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. diff --git a/test/tesla/adapter/mint_test.exs b/test/tesla/adapter/mint_test.exs index 8ac79783..a6d12f50 100644 --- a/test/tesla/adapter/mint_test.exs +++ b/test/tesla/adapter/mint_test.exs @@ -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 @@ -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 @@ -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