From 97916d7e5602888d53237ee7b297a18b836a1047 Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Wed, 8 Jul 2015 09:17:05 -0400 Subject: [PATCH] recv_timeout add HTTPoison http client adapter that overrides certain bad defaults remove the now unnecessary test http client update httpoison adapter with a better default recv_timeout defaults now work on both 0.6 and 0.7 versions of httpoison --- README.md | 2 +- config/test.exs | 2 +- lib/ex_aws/config/defaults.ex | 6 +-- lib/ex_aws/request/httpoison.ex | 37 +++++++++++++++++++ .../{httpotion_client.ex => httpotion.ex} | 0 mix.exs | 2 +- mix.lock | 4 +- test/default_helper.exs | 8 ---- 8 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 lib/ex_aws/request/httpoison.ex rename lib/ex_aws/request/{httpotion_client.ex => httpotion.ex} (100%) diff --git a/README.md b/README.md index e907a61d..a12841da 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ def deps do [ ex_aws: "~> 0.4.0", poison: "~> 1.2.0", - httpoison: "~> 0.6.0" + httpoison: "~> 0.7.0" ] end ``` diff --git a/config/test.exs b/config/test.exs index a7cbc922..d2a41e95 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,6 +1,6 @@ use Mix.Config config :ex_aws, - http_client: Test.HTTPClient, + http_client: ExAws.Request.HTTPoison, json_codec: Test.JSONCodec config :ex_aws, :kinesis, diff --git a/lib/ex_aws/config/defaults.ex b/lib/ex_aws/config/defaults.ex index 3a5b0367..bcecf788 100644 --- a/lib/ex_aws/config/defaults.ex +++ b/lib/ex_aws/config/defaults.ex @@ -9,7 +9,7 @@ defmodule ExAws.Config.Defaults do end def defaults(:dev) do [ - http_client: HTTPoison, + http_client: ExAws.Request.HTTPoison, json_codec: Poison, kinesis: [ scheme: "https://", @@ -38,7 +38,7 @@ defmodule ExAws.Config.Defaults do end def defaults(:test) do [ - http_client: HTTPoison, + http_client: ExAws.Request.HTTPoison, json_codec: Poison, dynamodb: [ scheme: "http://", @@ -50,7 +50,7 @@ defmodule ExAws.Config.Defaults do end def defaults(:prod) do [ - http_client: HTTPoison, + http_client: ExAws.Request.HTTPoison, json_codec: Poison, kinesis: [ scheme: "https://", diff --git a/lib/ex_aws/request/httpoison.ex b/lib/ex_aws/request/httpoison.ex new file mode 100644 index 00000000..99e8795e --- /dev/null +++ b/lib/ex_aws/request/httpoison.ex @@ -0,0 +1,37 @@ +defmodule ExAws.Request.HTTPoison do + @behaviour ExAws.Request.HttpClient + + @moduledoc """ + Configuration for HTTPoison + + Options can set for HTTPoison with the following config + + HTTPoison 0.7.X + ``` + config :ex_aws, :httpoison_opts, + recv_timeout: 30_000 + ``` + + HTTPoison 0.6.X + ``` + config :ex_aws, :httpoison_opts, + hackney: [recv_timeout: 30_000] + ``` + + The default config handles setting both of the above + """ + + @default_timeout 30_000 + + # The recv_timeout is repeated inside :hackney because in 0.6.X of + # HTTPoison it couldn't be set as an option to httpoison directly. + @default_opts [ + recv_timeout: @default_timeout, + hackney: [recv_timeout: @default_timeout] + ] + + def request(method, url, body, headers) do + opts = Application.get_env(:ex_aws, :httpoison_opts, @default_opts) + HTTPoison.request(method, url, body, headers, opts) + end +end diff --git a/lib/ex_aws/request/httpotion_client.ex b/lib/ex_aws/request/httpotion.ex similarity index 100% rename from lib/ex_aws/request/httpotion_client.ex rename to lib/ex_aws/request/httpotion.ex diff --git a/mix.exs b/mix.exs index 12caa9ea..e5dddfbc 100644 --- a/mix.exs +++ b/mix.exs @@ -31,7 +31,7 @@ defmodule ExAws.Mixfile do {:earmark, "~> 0.1", only: :dev}, {:ex_doc, "~> 0.7", only: :dev}, {:sweet_xml, "~> 0.2.1", only: [:test]}, - {:httpoison, "~> 0.6.0", only: [:test, :dev]}, + {:httpoison, "~> 0.7", only: [:test, :dev]}, {:poison, "~> 1.2.0", only: [:test, :dev]}, {:ibrowse, github: "cmullaparthi/ibrowse", tag: "v4.1.1", only: :test}, {:httpotion, "~> 2.0.0", only: :test}, diff --git a/mix.lock b/mix.lock index 4c019d80..a8118b2b 100644 --- a/mix.lock +++ b/mix.lock @@ -1,7 +1,7 @@ %{"earmark": {:hex, :earmark, "0.1.17"}, "ex_doc": {:hex, :ex_doc, "0.7.3"}, - "hackney": {:hex, :hackney, "1.1.0"}, - "httpoison": {:hex, :httpoison, "0.6.2"}, + "hackney": {:hex, :hackney, "1.2.0"}, + "httpoison": {:hex, :httpoison, "0.7.0"}, "httpotion": {:hex, :httpotion, "2.0.0"}, "ibrowse": {:git, "git://github.com/cmullaparthi/ibrowse.git", "d2e369ff42666c3574b8b7ec26f69027895c4d94", [tag: "v4.1.1"]}, "idna": {:hex, :idna, "1.0.2"}, diff --git a/test/default_helper.exs b/test/default_helper.exs index e6b071ec..3a8b3dd2 100644 --- a/test/default_helper.exs +++ b/test/default_helper.exs @@ -20,14 +20,6 @@ end ## Other -defmodule Test.HTTPClient do - @behaviour ExAws.Request.HttpClient - - def request(method, url, body, headers) do - HTTPoison.request(method, url, body, headers) - end -end - defmodule Test.JSONCodec do @behaviour ExAws.JSON.Codec