diff options
| author | Magnus Ahltorp <map@kth.se> | 2015-01-29 23:45:44 +0100 |
|---|---|---|
| committer | Magnus Ahltorp <map@kth.se> | 2015-01-29 23:45:44 +0100 |
| commit | ccf6ee448964ebeaf733eeb515d2bb8005d0c6f2 (patch) | |
| tree | 1b85ca39457298b656e1f5ddf52269f09ef38927 | |
| parent | dd9dcfa363f6219d30b5f229fa8097c03395698e (diff) | |
Use hackney instead of inets:httpc
| -rw-r--r-- | src/plop.erl | 20 | ||||
| -rw-r--r-- | src/plop_app.erl | 1 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/plop.erl b/src/plop.erl index 821fe99..d2a8fc3 100644 --- a/src/plop.erl +++ b/src/plop.erl @@ -193,6 +193,18 @@ storage_nodes_quorum() -> {ok, Value} = application:get_env(plop, storage_nodes_quorum), Value. +send_http_request(URL, Headers, RequestBody) -> + ParentPid = self(), + RequestId = make_ref(), + CACertFile = application:get_env(catlfish, https_cacertfile, none), + spawn(fun () -> + {ok, StatusCode, RespHeaders, ClientRef} = hackney:post(URL, Headers, RequestBody, [{ssl_options, [{cacertfile, CACertFile}]}]), + {ok, Body} = hackney:body(ClientRef), + StatusLine = {none, StatusCode, none}, + ParentPid ! {http, {RequestId, {StatusLine, RespHeaders, Body}}} + end), + RequestId. + send_storage_sendentry(URLBase, LogEntry, TreeLeafHash) -> Request = mochijson2:encode( {[{plop_version, 1}, @@ -201,9 +213,7 @@ send_storage_sendentry(URLBase, LogEntry, TreeLeafHash) -> ]}), lager:debug("leafhash ~s: send sendentry to storage node ~p", [mochihex:to_hex(TreeLeafHash), URLBase]), - {ok, RequestId} = httpc:request(post, {URLBase ++ "sendentry", [], - "text/json", list_to_binary(Request)}, - [], [{sync, false}]), + RequestId = send_http_request(URLBase ++ "sendentry", [{"Content-Type", "text/json"}], list_to_binary(Request)), {RequestId, URLBase}. send_storage_entrycommitted(URLBase, EntryHash, TreeLeafHash) -> @@ -212,9 +222,7 @@ send_storage_entrycommitted(URLBase, EntryHash, TreeLeafHash) -> {entryhash, base64:encode(EntryHash)}, {treeleafhash, base64:encode(TreeLeafHash)} ]}), - httpc:request(post, {URLBase ++ "entrycommitted", [], - "text/json", list_to_binary(Request)}, - [], [{sync, false}]). + send_http_request(URLBase ++ "entrycommitted", [{"Content-Type", "text/json"}], list_to_binary(Request)). store_loop(TreeLeafHash, Requests, RepliesUntilQuorum) -> receive diff --git a/src/plop_app.erl b/src/plop_app.erl index 767bf06..9cb5558 100644 --- a/src/plop_app.erl +++ b/src/plop_app.erl @@ -6,6 +6,7 @@ -export([start/2, stop/1]). start(normal, Args) -> + hackney:start(), plop_sup:start_link(Args). stop(_State) -> |
