]> granicus.if.org Git - ejabberd/commitdiff
Use correct headers in rest calls
authorPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 23 Apr 2018 10:29:50 +0000 (12:29 +0200)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 23 Apr 2018 10:29:56 +0000 (12:29 +0200)
src/rest.erl

index 18bf1b5ee5dff45c34d0366f30bf80109db1b2ad..99501ae566f19e4ff393660d5a7080388f03da87 100644 (file)
@@ -58,32 +58,32 @@ with_retry(Method, Args, Retries, MaxRetries, Backoff) ->
     end.
 
 get(Server, Path) ->
-    request(Server, get, Path, [], "application/json", <<>>).
+    request(Server, get, Path, [], <<"application/json">>, <<>>).
 get(Server, Path, Params) ->
-    request(Server, get, Path, Params, "application/json", <<>>).
+    request(Server, get, Path, Params, <<"application/json">>, <<>>).
 
 delete(Server, Path) ->
-    request(Server, delete, Path, [], "application/json", <<>>).
+    request(Server, delete, Path, [], <<"application/json">>, <<>>).
 
 post(Server, Path, Params, Content) ->
     Data = encode_json(Content),
-    request(Server, post, Path, Params, "application/json", Data).
+    request(Server, post, Path, Params, <<"application/json">>, Data).
 
 put(Server, Path, Params, Content) ->
     Data = encode_json(Content),
-    request(Server, put, Path, Params, "application/json", Data).
+    request(Server, put, Path, Params, <<"application/json">>, Data).
 
 patch(Server, Path, Params, Content) ->
     Data = encode_json(Content),
-    request(Server, patch, Path, Params, "application/json", Data).
+    request(Server, patch, Path, Params, <<"application/json">>, Data).
 
 request(Server, Method, Path, Params, Mime, Data) ->
     URI = url(Server, Path, Params),
     Opts = [{connect_timeout, ?CONNECT_TIMEOUT},
             {timeout, ?HTTP_TIMEOUT}],
-    Hdrs = [{"connection", "keep-alive"},
-            {"content-type", Mime},
-            {"User-Agent", "ejabberd"}],
+    Hdrs = [{<<"connection">>, <<"keep-alive">>},
+           {<<"content-type">>, Mime},
+           {<<"User-Agent">>, <<"ejabberd">>}],
     Begin = os:timestamp(),
     Result = case catch p1_http:request(Method, URI, Hdrs, Data, Opts) of
         {ok, Code, _, <<>>} ->
@@ -174,13 +174,13 @@ base_url(Server, Path) ->
     end.
 
 url(Url, []) ->
-    binary_to_list(Url);
+    Url;
 url(Url, Params) ->
     L = [<<"&", (iolist_to_binary(Key))/binary, "=",
           (misc:url_encode(Value))/binary>>
             || {Key, Value} <- Params],
     <<$&, Encoded/binary>> = iolist_to_binary(L),
-    binary_to_list(<<Url/binary, $?, Encoded/binary>>).
+    <<Url/binary, $?, Encoded/binary>>.
 url(Server, Path, Params) ->
     case binary:split(base_url(Server, Path), <<"?">>) of
         [Url] ->