summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/catlfish_sup.erl9
-rw-r--r--src/catlfish_web.erl33
2 files changed, 26 insertions, 16 deletions
diff --git a/src/catlfish_sup.erl b/src/catlfish_sup.erl
index 353b691..8b43faf 100644
--- a/src/catlfish_sup.erl
+++ b/src/catlfish_sup.erl
@@ -21,18 +21,17 @@ permanent_worker(Name, StartFunc, Modules) ->
gen_http_config(Config, SSLOptions, SSLFlag) ->
{ChildName, IpAddress, Port, Module} = Config,
- {ok, IPv4Address} =
- inet:parse_ipv4strict_address(IpAddress),
+ {ok, IPv4Address} = inet:parse_ipv4strict_address(IpAddress),
WebConfig = [{ip, IPv4Address},
{port, Port},
{ssl, SSLFlag},
- {acceptor_pool_size, application:get_env(catlfish, http_server_pool_size, 16)},
+ {acceptor_pool_size,
+ application:get_env(catlfish, http_server_pool_size, 16)},
{ssl_opts, SSLOptions}
],
{ChildName,
{catlfish_web, start, [WebConfig, Module, ChildName]},
- permanent, 5000,
- worker, dynamic}.
+ permanent, 5000, worker, dynamic}.
init([]) ->
SSLOptions =
diff --git a/src/catlfish_web.erl b/src/catlfish_web.erl
index d49aaa1..e541a9b 100644
--- a/src/catlfish_web.erl
+++ b/src/catlfish_web.erl
@@ -26,39 +26,49 @@ loop(Req, Module) ->
'GET' ->
Query = Req:parse_qs(),
{_, RawQuery, _} = mochiweb_util:urlsplit_path(Req:get(raw_path)),
- Result = case http_auth:verify_auth(AuthHeader, "GET", "/" ++ Path, RawQuery) of
+ Result = case http_auth:verify_auth(AuthHeader, "GET",
+ "/" ++ Path, RawQuery) of
failure ->
- {403, [{"Content-Type", "text/plain"}], "Invalid credentials"};
+ {403, [{"Content-Type", "text/plain"}],
+ "Invalid credentials"};
success ->
lager:debug("GET ~p ~p", [Path, Query]),
- add_auth("/" ++ Path, Module:request(get, Path, Query));
+ add_auth("/" ++ Path,
+ Module:request(get, Path, Query));
noauth ->
lager:debug("GET ~p ~p", [Path, Query]),
Module:request(get, Path, Query)
end,
- lager:debug("GET finished: ~p us", [timer:now_diff(os:timestamp(), Starttime)]),
+ lager:debug("GET finished: ~p us",
+ [timer:now_diff(os:timestamp(), Starttime)]),
case Result of
none ->
- Req:respond({404, [{"Content-Type", "text/plain"}], "Page not found"});
+ Req:respond({404, [{"Content-Type", "text/plain"}],
+ "Page not found"});
_ ->
Req:respond(Result)
end;
'POST' ->
Body = Req:recv_body(),
- Result = case http_auth:verify_auth(AuthHeader, "POST", "/" ++ Path, Body) of
+ Result = case http_auth:verify_auth(AuthHeader, "POST",
+ "/" ++ Path, Body) of
failure ->
- {403, [{"Content-Type", "text/plain"}], "Invalid credentials"};
+ {403, [{"Content-Type", "text/plain"}],
+ "Invalid credentials"};
success ->
lager:debug("POST ~p ~p", [Path, Body]),
- add_auth("/" ++ Path, Module:request(post, Path, Body));
+ add_auth("/" ++ Path,
+ Module:request(post, Path, Body));
noauth ->
lager:debug("POST ~p ~p", [Path, Body]),
Module:request(post, Path, Body)
end,
- lager:debug("POST finished: ~p us", [timer:now_diff(os:timestamp(), Starttime)]),
+ lager:debug("POST finished: ~p us",
+ [timer:now_diff(os:timestamp(), Starttime)]),
case Result of
none ->
- Req:respond({404, [{"Content-Type", "text/plain"}], "Page not found"});
+ Req:respond({404, [{"Content-Type", "text/plain"}],
+ "Page not found"});
_ ->
Req:respond(Result)
end;
@@ -68,7 +78,8 @@ loop(Req, Module) ->
catch
Type:What ->
[CrashFunction | Stack] = erlang:get_stacktrace(),
- lager:error("Crash in ~p for path ~p: ~p ~p~n~p~n~p~n", [Module, Path, Type, What, CrashFunction, Stack]),
+ lager:error("Crash in ~p for path ~p: ~p ~p~n~p~n~p~n",
+ [Module, Path, Type, What, CrashFunction, Stack]),
Req:respond({500, [{"Content-Type", "text/plain"}],
"Internal Server Error\n"})
end.