summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Branca <chewbranca@apache.org>2017-12-14 20:26:22 +0000
committerRussell Branca <chewbranca@apache.org>2017-12-14 20:26:22 +0000
commitf91b1812c7cad81d6df8c3c68bcb3dfe7b5f95d8 (patch)
tree79bc70d7c42358d9a24d384db6aac3d92e15094b
parent5bce2d98a298c25b77d8dcda19deeedb494cc289 (diff)
downloadcouchdb-f91b1812c7cad81d6df8c3c68bcb3dfe7b5f95d8.tar.gz
Port httpotion functionality until released
-rw-r--r--elixir_suite/lib/couch.ex38
1 files changed, 36 insertions, 2 deletions
diff --git a/elixir_suite/lib/couch.ex b/elixir_suite/lib/couch.ex
index d879ecf5e..511901107 100644
--- a/elixir_suite/lib/couch.ex
+++ b/elixir_suite/lib/couch.ex
@@ -27,8 +27,13 @@ defmodule Couch do
end
end
- def process_response_body(body) do
- body |> IO.iodata_to_binary |> :jiffy.decode([:return_maps])
+ def process_response_body(headers, body) do
+ case headers[:'content-type'] do
+ "application/json" ->
+ body |> IO.iodata_to_binary |> :jiffy.decode([:return_maps])
+ _ ->
+ process_response_body(body)
+ end
end
def login(user, pass) do
@@ -36,4 +41,33 @@ defmodule Couch do
true = resp.body["ok"]
resp.body
end
+
+ # HACK: this is here until this commit lands in a release
+ # https://github.com/myfreeweb/httpotion/commit/f3fa2f0bc3b9b400573942b3ba4628b48bc3c614
+ def handle_response(response) do
+ case response do
+ { :ok, status_code, headers, body, _ } ->
+ processed_headers = process_response_headers(headers)
+ %HTTPotion.Response{
+ status_code: process_status_code(status_code),
+ headers: processed_headers,
+ body: process_response_body(processed_headers, body)
+ }
+ { :ok, status_code, headers, body } ->
+ processed_headers = process_response_headers(headers)
+ %HTTPotion.Response{
+ status_code: process_status_code(status_code),
+ headers: processed_headers,
+ body: process_response_body(processed_headers, body)
+ }
+ { :ibrowse_req_id, id } ->
+ %HTTPotion.AsyncResponse{ id: id }
+ { :error, { :conn_failed, { :error, reason }}} ->
+ %HTTPotion.ErrorResponse{ message: error_to_string(reason)}
+ { :error, :conn_failed } ->
+ %HTTPotion.ErrorResponse{ message: "conn_failed"}
+ { :error, reason } ->
+ %HTTPotion.ErrorResponse{ message: error_to_string(reason)}
+ end
+ end
end