summaryrefslogtreecommitdiff
path: root/src/plop_httputil.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/plop_httputil.erl')
-rw-r--r--src/plop_httputil.erl47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/plop_httputil.erl b/src/plop_httputil.erl
index a7be8b5..2d840aa 100644
--- a/src/plop_httputil.erl
+++ b/src/plop_httputil.erl
@@ -27,24 +27,29 @@ request(DebugTag, URL, Headers, RequestBody) ->
#hackney_url{path = Path} = ParsedURL,
lager:debug("~s: sending http request to ~p",
[DebugTag, URL]),
- {ok, ConnRef} = hackney:connect(ParsedURL, [{ssl_options, [{cacertfile, CACertFile}]}]),
- lager:debug("~s: connected to ~p",
- [DebugTag, URL]),
- {ok, StatusCode, RespHeaders, ClientRef} =
- hackney:send_request(ConnRef,
- {post, Path,
- add_auth("POST", Path, Headers,
- RequestBody),
- RequestBody}),
- lager:debug("~s: received headers for ~p: ~p",
- [DebugTag, URL, RespHeaders]),
- {ok, Body} = hackney:body(ClientRef),
- Stoptime = os:timestamp(),
- hackney:close(ClientRef),
- lager:debug("~s: received body for ~p: time ~p",
- [DebugTag, URL, timer:now_diff(Stoptime, Starttime)]),
- StatusLine = {none, StatusCode, none},
- AuthHeader = get_auth_header(hackney_headers:new(RespHeaders)),
- {http_auth:verify_auth(AuthHeader, "REPLY",
- binary_to_list(Path), Body),
- StatusLine, RespHeaders, Body}.
+ case hackney:connect(ParsedURL,
+ [{ssl_options, [{cacertfile, CACertFile}]}]) of
+ {ok, ConnRef} ->
+ lager:debug("~s: connected to ~p",
+ [DebugTag, URL]),
+ {ok, StatusCode, RespHeaders, ClientRef} =
+ hackney:send_request(ConnRef,
+ {post, Path,
+ add_auth("POST", Path, Headers,
+ RequestBody),
+ RequestBody}),
+ lager:debug("~s: received headers for ~p: ~p",
+ [DebugTag, URL, RespHeaders]),
+ {ok, Body} = hackney:body(ClientRef),
+ Stoptime = os:timestamp(),
+ hackney:close(ClientRef),
+ lager:debug("~s: received body for ~p: time ~p",
+ [DebugTag, URL, timer:now_diff(Stoptime, Starttime)]),
+ StatusLine = {none, StatusCode, none},
+ AuthHeader = get_auth_header(hackney_headers:new(RespHeaders)),
+ {http_auth:verify_auth(AuthHeader, "REPLY",
+ binary_to_list(Path), Body),
+ StatusLine, RespHeaders, Body};
+ {error, Error} ->
+ {error, Error}
+ end.