Skip to content

Commit

Permalink
timeout mapped to recv timeout for hackney adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Oct 14, 2023
1 parent aaa0300 commit f3c9757
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/docker_engine_api/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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, [])
Expand All @@ -74,25 +71,29 @@ 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}
| middleware
]
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

0 comments on commit f3c9757

Please sign in to comment.