diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2020-08-05 00:04:58 -0400 |
---|---|---|
committer | Hubert Chathi <hubert@uhoreg.ca> | 2020-08-05 00:04:58 -0400 |
commit | ebaaddf076097268a3430728695eca146395165d (patch) | |
tree | 1d78104f85642111e0a1254940536eeaf2a34803 /lib | |
parent | minor code improvements (diff) |
check that the server response has a JSON content-type
Diffstat (limited to 'lib')
-rw-r--r-- | lib/polyjuice/client/endpoint.ex | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/polyjuice/client/endpoint.ex b/lib/polyjuice/client/endpoint.ex index b75ee6c..41c0a86 100644 --- a/lib/polyjuice/client/endpoint.ex +++ b/lib/polyjuice/client/endpoint.ex @@ -87,8 +87,14 @@ defmodule Polyjuice.Client.Endpoint do ) :: any def parse_response(%{} = endpoint_args, status_code, headers, body) when is_integer(status_code) and is_list(headers) and is_binary(body) do - # FIXME: check if content type is "application/json" - with {:ok, json} <- Jason.decode(body) do + # make sure it's JSON content + with {_, "application/json"} <- + Enum.find( + headers, + {nil, nil}, + fn {name, _} -> String.downcase(name, :ascii) == "content-type" end + ), + {:ok, json} <- Jason.decode(body) do case status_code do 200 -> Polyjuice.Client.Endpoint.BodyParser.parse(endpoint_args, json) |