summaryrefslogtreecommitdiffstats
path: root/src/httpabs.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/httpabs.erl')
-rw-r--r--src/httpabs.erl28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/httpabs.erl b/src/httpabs.erl
index bc9e068..152621e 100644
--- a/src/httpabs.erl
+++ b/src/httpabs.erl
@@ -6,9 +6,9 @@
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
-%
+%
% http://www.apache.org/licenses/LICENSE-2.0
-%
+%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,7 @@
-module(httpabs).
-export([get/2,
post/4, %I miss python's default arguments..
- post/5,
+ post/5,
put/4,
delete/2
]).
@@ -29,10 +29,10 @@
-define(SC(L), util:concat(L)).
%NOTE
-%Consider the Erlang statement:
+%Consider the Erlang statement:
%
%{ok, {{"HTTP/1.1",ReturnCode, State}, Head, Body}} = httpc:get(URL).
-%CDAP returns error messages in the “Body” field above.
+%CDAP returns error messages in the “Body” field above.
%
%However, Consul:
%1) Always (in all HTTP failures I’ve tested) returns Body == “500\n”
@@ -51,21 +51,21 @@
%%%
-spec parse_response({error|ok, any()}, string()) -> httpstat().
parse_response({Status, Response}, URL) ->
- case Status of
- error ->
+ case Status of
+ error ->
lager:error("httpc error: cannot hit: ~s", [URL]),
case Response of
no_scheme -> {400, io_lib:format("ERROR: The following URL is malformed: ~s", [URL])};
{bad_body, _} -> {400, "ERROR: The request Body is malformed"};
{bad_body_generator,_} -> {400, "ERROR: The request Body is malformed"};
_ ->
- lager:error(io_lib:format("Unexpected ERROR hitting ~s", [URL])),
+ lager:error(io_lib:format("Unexpected ERROR hitting ~s", [URL])),
{504, list_to_binary(io_lib:format("ERROR: The following URL is unreachable or the request was unable to be parsed due to an unknown error: ~s", [URL]))} %Are there other reasons other than bad body and unreachable that crash request? (Sneak peak: the answer is probably)
end;
- ok ->
+ ok ->
{{_, ReturnCode, State}, _Head, Body} = Response,
- case ReturnCode of
- 200 ->
+ case ReturnCode of
+ 200 ->
{ReturnCode, Body};
_ ->
lager:error("Error While hitting ~s, Non-200 status code returned. HTTP Code ~p, State ~s, ResponseBody ~s:", [URL, ReturnCode, State, Body]),
@@ -77,14 +77,14 @@ parse_response({Status, Response}, URL) ->
sanitize(URL) ->
%allow URL to look like "www.foo.com" or <<"www.foo.com">>, trim it
- case is_binary(URL) of
+ case is_binary(URL) of
true -> string:strip(binary_to_list(URL));
false -> string:strip(URL)
end.
%anywhere you see any() is essentially lazy typing.. fix these someday when time is abundant
-spec post(string(), string()|binary(), string(), any()) -> httpstat().
-post(XER, URL, ContentType, Body) ->
+post(XER, URL, ContentType, Body) ->
%post that sends the XER, no headers signature
Headers = [{"x-ecomp-requestid", XER}],
U = sanitize(URL),
@@ -97,7 +97,7 @@ post(XER, URL, Headers, ContentType, Body) ->
parse_response(httpc:request(post, {U, [{"x-ecomp-requestid", XER} | Headers], ContentType, Body}, [],[]), U).
-spec get(string(), string()|binary()) -> httpstat().
-get(XER, URL) ->
+get(XER, URL) ->
%http get that always sends the XER.. even if the server doesn't want it; maybe this will blow up on me one day.
U = sanitize(URL),
Headers = [{"x-ecomp-requestid", XER}],