couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iil...@apache.org
Subject [34/50] couch-httpd commit: updated refs/heads/split_out_httpd_stack to e44a372
Date Tue, 01 Mar 2016 20:01:07 GMT
Use Stack to select http handlers


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/commit/675e3c70
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/tree/675e3c70
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/diff/675e3c70

Branch: refs/heads/split_out_httpd_stack
Commit: 675e3c70b80b623f5953a88c01a1edf803661531
Parents: 2731706
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Fri Feb 26 13:44:36 2016 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Mar 1 08:35:09 2016 -0800

----------------------------------------------------------------------
 src/couch_httpd_handler.erl  |  5 ++---
 src/couch_httpd_handlers.erl | 29 ++++++++++++++++-------------
 2 files changed, 18 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/675e3c70/src/couch_httpd_handler.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_handler.erl b/src/couch_httpd_handler.erl
index 6b106a1..0e95c8a 100644
--- a/src/couch_httpd_handler.erl
+++ b/src/couch_httpd_handler.erl
@@ -201,7 +201,7 @@ after_request(HttpReq, HttpResp0) ->
     maybe_log(HttpReq, HttpResp2),
     HttpResp2.
 
-process_request(#httpd{mochi_req = MochiReq} = HttpReq) ->
+process_request(#httpd{mochi_req = MochiReq, stack = Stack} = HttpReq) ->
     HandlerKey =
         case HttpReq#httpd.path_parts of
             [] -> <<>>;
@@ -217,8 +217,7 @@ process_request(#httpd{mochi_req = MochiReq} = HttpReq) ->
         not_preflight ->
             case couch_httpd_auth_plugin:authenticate(HttpReq, fun authenticate_request/1)
of
             #httpd{} = Req ->
-                HandlerFun = couch_httpd_handlers:url_handler(
-                    HandlerKey, fun chttpd_db:handle_request/1),
+                HandlerFun = couch_httpd_handlers:url_handler(HandlerKey, Stack),
                 AuthorizedReq = couch_httpd_auth_plugin:authorize(possibly_hack(Req),
                     fun chttpd_auth_request:authorize_request/1),
                 {AuthorizedReq, HandlerFun(AuthorizedReq)};

http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/675e3c70/src/couch_httpd_handlers.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_handlers.erl b/src/couch_httpd_handlers.erl
index 3a49ca6..73c1790 100644
--- a/src/couch_httpd_handlers.erl
+++ b/src/couch_httpd_handlers.erl
@@ -15,10 +15,10 @@
 -export([
     url_handler/2,
     db_handler/2,
-    design_handler/2
+    design_handler/2,
+    select/4
 ]).
 
--define(SERVICE_ID, chttpd_handlers).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -26,26 +26,29 @@
 %% API Function Definitions
 %% ------------------------------------------------------------------
 
-url_handler(HandlerKey, DefaultFun) ->
-    select(collect(url_handler, [HandlerKey]), DefaultFun).
+url_handler(HandlerKey, Stack) ->
+    Stack:url_handler(HandlerKey).
 
-db_handler(HandlerKey, DefaultFun) ->
-    select(collect(db_handler, [HandlerKey]), DefaultFun).
+db_handler(HandlerKey, Stack) ->
+    Stack:db_handler(HandlerKey).
 
-design_handler(HandlerKey, DefaultFun) ->
-    select(collect(design_handler, [HandlerKey]), DefaultFun).
+design_handler(HandlerKey, Stack) ->
+    Stack:design_handler(HandlerKey).
+
+select(ServiceID, Func, HandlerKey, Default) ->
+    select(collect(ServiceID, Func, [HandlerKey]), Default).
 
 %% ------------------------------------------------------------------
 %% Internal Function Definitions
 %% ------------------------------------------------------------------
 
-collect(Func, Args) ->
-    Results = do_apply(Func, Args, []),
+collect(ServiceID, Func, Args) ->
+    Results = do_apply(ServiceID, Func, Args, []),
     [HandlerFun || HandlerFun <- Results, HandlerFun /= no_match].
 
-do_apply(Func, Args, Opts) ->
-    Handle = couch_epi:get_handle(?SERVICE_ID),
-    couch_epi:apply(Handle, ?SERVICE_ID, Func, Args, Opts).
+do_apply(ServiceID, Func, Args, Opts) ->
+    Handle = couch_epi:get_handle(ServiceID),
+    couch_epi:apply(Handle, ServiceID, Func, Args, Opts).
 
 select([], Default) ->
     Default;


Mime
View raw message