summaryrefslogtreecommitdiff
path: root/src/catlfish_web.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/catlfish_web.erl')
-rw-r--r--src/catlfish_web.erl21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/catlfish_web.erl b/src/catlfish_web.erl
index e541a9b..ea34928 100644
--- a/src/catlfish_web.erl
+++ b/src/catlfish_web.erl
@@ -17,8 +17,19 @@ add_auth(Path, {Code, Headers, Data}) ->
lager:debug("sent auth header: ~p", [AuthHeader]),
{Code, [{"X-Catlfish-Auth", AuthHeader} | Headers], Data}.
+split_path([]) ->
+ {[], []};
+split_path([E]) ->
+ {E, []};
+split_path(Parts) ->
+ [Fun | AppRev] = lists:reverse(Parts),
+ App = string:join(lists:reverse(AppRev), "/"),
+ {Fun, App}.
+
loop(Req, Module) ->
- "/" ++ Path = Req:get(path),
+ "/" ++ Path = Req:get(path), % FIXME no need to strip "/"
+ {Fun, App} = split_path(string:tokens(Path, "/")),
+ lager:debug("Fun=~s; App=~s;", [Fun, App]),
try
Starttime = os:timestamp(),
AuthHeader = Req:get_header_value("X-Catlfish-Auth"),
@@ -34,10 +45,10 @@ loop(Req, Module) ->
success ->
lager:debug("GET ~p ~p", [Path, Query]),
add_auth("/" ++ Path,
- Module:request(get, Path, Query));
+ Module:request(get, App, Fun, Query));
noauth ->
lager:debug("GET ~p ~p", [Path, Query]),
- Module:request(get, Path, Query)
+ Module:request(get, App, Fun, Query)
end,
lager:debug("GET finished: ~p us",
[timer:now_diff(os:timestamp(), Starttime)]),
@@ -58,10 +69,10 @@ loop(Req, Module) ->
success ->
lager:debug("POST ~p ~p", [Path, Body]),
add_auth("/" ++ Path,
- Module:request(post, Path, Body));
+ Module:request(post, App, Fun, Body));
noauth ->
lager:debug("POST ~p ~p", [Path, Body]),
- Module:request(post, Path, Body)
+ Module:request(post, App, Fun, Body)
end,
lager:debug("POST finished: ~p us",
[timer:now_diff(os:timestamp(), Starttime)]),