You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2017/12/12 21:28:28 UTC
[couchdb] 02/03: WIP garbagy commit
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch elixir-suite-davisp
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 41e8a0acb29c2116b12ab05f2847fef6dddb4620
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Dec 12 15:27:13 2017 -0600
WIP garbagy commit
Part of this needs pulled out once we update our HTTPotion release
version to use whatever is after @chewbranca's commit. Some of it needs
to not be un-merged if memory serves maybe.
---
elixir_suite/lib/couch.ex | 46 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 40 insertions(+), 6 deletions(-)
diff --git a/elixir_suite/lib/couch.ex b/elixir_suite/lib/couch.ex
index d879ecf..e6f9cfc 100644
--- a/elixir_suite/lib/couch.ex
+++ b/elixir_suite/lib/couch.ex
@@ -10,13 +10,16 @@ defmodule Couch do
end
def process_request_headers(headers) do
- headers
- |> Dict.put(:"User-Agent", "couch-potion")
- |> Dict.put(:"Content-Type", "application/json")
+ headers = Keyword.put(headers, :"User-Agent", "couch-potion")
+ if headers[:"Content-Type"] do
+ headers
+ else
+ Keyword.put(headers, :"Content-Type", "application/json")
+ end
end
def process_options(options) do
- Dict.put options, :basic_auth, {"adm", "pass"}
+ Keyword.put options, :basic_auth, {"adm", "pass"}
end
def process_request_body(body) do
@@ -27,8 +30,39 @@ defmodule Couch do
end
end
- def process_response_body(body) do
- body |> IO.iodata_to_binary |> :jiffy.decode([:return_maps])
+ def handle_response(response) do
+ case response do
+ { :ok, status_code, headers, body, _ } ->
+ headers = process_response_headers(headers)
+ %HTTPotion.Response{
+ status_code: process_status_code(status_code),
+ headers: headers,
+ body: process_response_body(headers, body)
+ }
+ { :ok, status_code, headers, body } ->
+ headers = process_response_headers(headers)
+ %HTTPotion.Response{
+ status_code: process_status_code(status_code),
+ headers: headers,
+ body: process_response_body(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
+
+ def process_response_body(headers, body) do
+ if String.match?(headers[:"Content-Type"], ~r/application\/json/) do
+ body |> IO.iodata_to_binary |> :jiffy.decode([:return_maps])
+ else
+ body |> IO.iodata_to_binary
+ end
end
def login(user, pass) do
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.