From 1ca369b723fa1c601f51cce871e22db1e18b5e8c Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Fri, 13 Nov 2015 15:59:29 +0100 Subject: Parametrise "application part" of URL. Breaking out "ct/v1" to a separate argument to request(). Good for other applications. --- src/catlfish_web.erl | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/catlfish_web.erl') 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)]), -- cgit v1.1