summaryrefslogtreecommitdiff
path: root/src/catlfish_web.erl
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2015-11-13 15:59:29 +0100
committerLinus Nordberg <linus@nordu.net>2015-11-13 15:59:29 +0100
commit1ca369b723fa1c601f51cce871e22db1e18b5e8c (patch)
tree3c4a541beafd71eb1bd9490d90abc82d452ea654 /src/catlfish_web.erl
parentce66c555c35e17c1ca0e0b4ff28056526183fceb (diff)
Parametrise "application part" of URL.
Breaking out "ct/v1" to a separate argument to request(). Good for other applications.
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)]),