couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject chttpd commit: updated refs/heads/master to 40cfa61
Date Fri, 14 Aug 2015 16:31:36 GMT
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master 238b8c482 -> 40cfa61bc


Support endpoint overriding

There are two kinds of overrides:
- overriding regular endpoint
- overriding default handler (such as chttpd_db:handle_request/1)

Therefore there are two distinct options for overriding.

    url_handler(<<"_all_dbs">>) ->
        {override, fun mymodule:handle_all_dbs_req/1};

    url_handler(_) ->
        {default, fun mymodule:handle_request/1};


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/40cfa61b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/40cfa61b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/40cfa61b

Branch: refs/heads/master
Commit: 40cfa61bc7c85703e9f4994b3f02eff82403aca1
Parents: 238b8c4
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Thu Aug 13 08:33:33 2015 -0700
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Thu Aug 13 08:42:46 2015 -0700

----------------------------------------------------------------------
 src/chttpd_handlers.erl | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/40cfa61b/src/chttpd_handlers.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_handlers.erl b/src/chttpd_handlers.erl
index 65f8b26..e21986b 100644
--- a/src/chttpd_handlers.erl
+++ b/src/chttpd_handlers.erl
@@ -30,22 +30,13 @@ provider(App, Module) ->
        App, chttpd_handlers, Module).
 
 url_handler(HandlerKey, DefaultFun) ->
-    case collect(url_handler, [HandlerKey]) of
-        [HandlerFun] -> HandlerFun;
-        [] -> DefaultFun
-    end.
+    select(collect(url_handler, [HandlerKey]), DefaultFun).
 
 db_handler(HandlerKey, DefaultFun) ->
-    case collect(db_handler, [HandlerKey]) of
-        [HandlerFun] -> HandlerFun;
-        [] -> DefaultFun
-    end.
+    select(collect(db_handler, [HandlerKey]), DefaultFun).
 
 design_handler(HandlerKey, DefaultFun) ->
-    case collect(design_handler, [HandlerKey]) of
-        [HandlerFun] -> HandlerFun;
-        [] -> DefaultFun
-    end.
+    select(collect(design_handler, [HandlerKey]), DefaultFun).
 
 %% ------------------------------------------------------------------
 %% Internal Function Definitions
@@ -58,3 +49,17 @@ collect(Func, Args) ->
 do_apply(Func, Args, Opts) ->
     Handle = couch_epi:get_handle(?MODULE),
     couch_epi:apply(Handle, chttpd, Func, Args, Opts).
+
+select([], Default) ->
+    Default;
+select([{default, OverrideDefault}], _Default) ->
+    OverrideDefault;
+select(Handlers, _Default) ->
+    select(Handlers).
+
+select([Handler]) ->
+    Handler;
+select([{override, Handler}|_]) ->
+    Handler;
+select([_Handler | Rest]) ->
+    select(Rest).


Mime
View raw message