You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2018/06/22 22:15:48 UTC
[couchdb] 19/31: Port httpotion functionality until released
This is an automated email from the ASF dual-hosted git repository.
chewbranca pushed a commit to branch elixir-suite
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit cae385afa74126c9a4dd1ca1dd9dfc1fecef4aed
Author: Russell Branca <ch...@apache.org>
AuthorDate: Thu Dec 14 20:26:22 2017 +0000
Port httpotion functionality until released
---
elixir_suite/lib/couch.ex | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/elixir_suite/lib/couch.ex b/elixir_suite/lib/couch.ex
index d879ecf..5119011 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