From f3c97575c041cc4ff75e9144bb42a58e15393f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarl=20Andr=C3=A9=20H=C3=BCbenthal?= Date: Sat, 14 Oct 2023 18:46:04 +0200 Subject: [PATCH] timeout mapped to recv timeout for hackney adapter --- lib/docker_engine_api/connection.ex | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/docker_engine_api/connection.ex b/lib/docker_engine_api/connection.ex index bc4dbf6..8a92b71 100644 --- a/lib/docker_engine_api/connection.ex +++ b/lib/docker_engine_api/connection.ex @@ -19,7 +19,7 @@ defmodule DockerEngineAPI.Connection do """ @type options :: [ {:base_url, String.t()}, - {:user_agent, String.t()}, + {:user_agent, String.t()} ] @doc "Forward requests to Tesla." @@ -41,22 +41,19 @@ defmodule DockerEngineAPI.Connection do def new(options \\ []) when is_list(options) do options = @default_options |> Keyword.merge(options) + options |> Keyword.merge(options) |> middleware() |> Tesla.client(adapter(options)) end - - - @doc """ Returns fully configured middleware for passing to Tesla.client/2. """ @spec middleware(options) :: [Tesla.Client.middleware()] def middleware(options \\ []) do base_url = Keyword.get(options, :base_url) - timeout = Keyword.get(options, :timeout, 1_000) tesla_options = get_tesla_options() middleware = Keyword.get(tesla_options, :middleware, []) @@ -74,7 +71,6 @@ defmodule DockerEngineAPI.Connection do ) [ - {Tesla.Middleware.Timeout, [timeout: timeout]}, {Tesla.Middleware.BaseUrl, base_url}, {Tesla.Middleware.Headers, [{"user-agent", user_agent}]}, {Tesla.Middleware.EncodeJson, engine: json_engine} @@ -82,17 +78,22 @@ defmodule DockerEngineAPI.Connection do ] end - def get_tesla_options, do: Application.get_env(:tesla, __MODULE__, []) @doc """ Returns the default adapter for this API. """ def adapter(options \\ []) do - Keyword.get( - options, - :adapter, - get_tesla_options() |> Keyword.get(:adapter, nil) - ) + case Keyword.get( + options, + :adapter, + get_tesla_options() |> Keyword.get(:adapter, nil) + ) do + Tesla.Adapter.Hackney -> + {Tesla.Adapter.Hackney, [recv_timeout: Keyword.get(options, :timeout, 1_000)]} + + other -> + other + end end end