From 2a14dc44d2b2f4f9bebb2738bc6e1ee39ca17fd8 Mon Sep 17 00:00:00 2001 From: Nick McKinney Date: Thu, 4 Feb 2021 17:40:25 -0500 Subject: [PATCH 1/6] Use HTTPoison error messaging in MISP.HTTP.handle_response/1 --- lib/http.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/http.ex b/lib/http.ex index 03b1042..2ce7999 100644 --- a/lib/http.ex +++ b/lib/http.ex @@ -83,8 +83,8 @@ defmodule MISP.HTTP do {:ok, %HTTPoison.Response{status_code: _, body: body}} -> {:error, body} - {:error, %HTTPoison.Error{reason: reason}} -> - {:error, "HTTP Error #{reason}"} + {:error, %HTTPoison.Error{} = e} -> + {:error, "HTTP Error #{HTTPoison.Error.message(e)}"} end end From 61b131507484b4bfbea88736edfe3933f85f751a Mon Sep 17 00:00:00 2001 From: Nick McKinney Date: Wed, 10 Feb 2021 10:16:56 -0500 Subject: [PATCH 2/6] Bump Jason to 1.2.x --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 024b85e..0e65e3c 100644 --- a/mix.exs +++ b/mix.exs @@ -36,7 +36,7 @@ defmodule MISP.MixProject do {:ex_doc, ">= 0.0.0", only: :dev}, {:typed_struct, "~> 0.1.4"}, {:accessible, "~> 0.2.1"}, - {:jason, "~> 1.1.2"} + {:jason, "~> 1.2"} ] end end From 28ce98c7f4181b35b92031d4062754404d9eda6d Mon Sep 17 00:00:00 2001 From: Nick McKinney Date: Wed, 10 Feb 2021 11:34:44 -0500 Subject: [PATCH 3/6] Update project dependencies --- mix.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mix.exs b/mix.exs index 0e65e3c..872696b 100644 --- a/mix.exs +++ b/mix.exs @@ -24,17 +24,17 @@ defmodule MISP.MixProject do # Run "mix help compile.app" to learn about applications. def application do [ - extra_applications: [:logger, :httpoison] + extra_applications: [:logger, :eex, :httpoison] ] end # Run "mix help deps" to learn about dependencies. defp deps do [ - {:httpoison, "~> 1.4"}, - {:poison, "~> 3.1"}, + {:httpoison, "~> 1.8"}, + {:poison, "~> 4.0.1"}, {:ex_doc, ">= 0.0.0", only: :dev}, - {:typed_struct, "~> 0.1.4"}, + {:typed_struct, "~> 0.2.1"}, {:accessible, "~> 0.2.1"}, {:jason, "~> 1.2"} ] From 99dd07b2652c729bc2fb54f7159b4f94fc77fe20 Mon Sep 17 00:00:00 2001 From: Nick McKinney Date: Wed, 10 Feb 2021 11:39:00 -0500 Subject: [PATCH 4/6] Allow application to set global client configuration --- lib/http.ex | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/http.ex b/lib/http.ex index 2ce7999..904f7c8 100644 --- a/lib/http.ex +++ b/lib/http.ex @@ -11,6 +11,11 @@ defmodule MISP.HTTP do ] end + defp defaults(), do: [timeout: 100 * 60] + defp client_options(options), do: Keyword.get(options, :client_options) + + defp client_config(options), do: Keyword.merge(defaults(), client_options(options)) + @doc """ An HTTP GET Request @@ -26,7 +31,7 @@ defmodule MISP.HTTP do |> URI.to_string() |> HTTPoison.get( headers(options), - timeout: 100 * 60 + client_config(options) ) |> handle_response() |> decode_response(decode_as) @@ -48,7 +53,7 @@ defmodule MISP.HTTP do |> HTTPoison.post( Poison.encode!(body), headers(options), - timeout: 100 * 60 + client_config(options) ) |> handle_response() |> decode_response(decode_as) @@ -69,7 +74,7 @@ defmodule MISP.HTTP do |> URI.to_string() |> HTTPoison.delete( headers(options), - timeout: 100 * 60 + client_config(options) ) |> handle_response() |> decode_response(nil) From 998836fb237bfeb9f57d7330a34a5cc64ba10a14 Mon Sep 17 00:00:00 2001 From: Nick McKinney Date: Wed, 10 Feb 2021 12:22:07 -0500 Subject: [PATCH 5/6] Get empty list for default client options --- lib/http.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/http.ex b/lib/http.ex index 904f7c8..3b27232 100644 --- a/lib/http.ex +++ b/lib/http.ex @@ -12,7 +12,7 @@ defmodule MISP.HTTP do end defp defaults(), do: [timeout: 100 * 60] - defp client_options(options), do: Keyword.get(options, :client_options) + defp client_options(options), do: Keyword.get(options, :client_options, []) defp client_config(options), do: Keyword.merge(defaults(), client_options(options)) From f2cde60576d7e3a3f1b60d10144a85239e8a8924 Mon Sep 17 00:00:00 2001 From: Nick McKinney Date: Mon, 22 Feb 2021 11:15:41 -0500 Subject: [PATCH 6/6] Cleanup code --- lib/http.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/http.ex b/lib/http.ex index 3b27232..5802ae2 100644 --- a/lib/http.ex +++ b/lib/http.ex @@ -12,9 +12,10 @@ defmodule MISP.HTTP do end defp defaults(), do: [timeout: 100 * 60] - defp client_options(options), do: Keyword.get(options, :client_options, []) + defp client_options(options), do: Keyword.get(options, :client_config, []) - defp client_config(options), do: Keyword.merge(defaults(), client_options(options)) + defp client_config(options), + do: Keyword.merge(defaults(), client_options(options)) @doc """ An HTTP GET Request