From 7a1efddfb663068d8ee59ee8f6c655777d4aa662 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Wed, 3 Feb 2010 16:30:08 +0000 Subject: add default_fun and url_handlers to #http. It's useful for any custom handler that need to use the http_handler and not only the db and design http handlers. Like for example in the rewriter. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@906111 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_db.hrl | 4 +++- src/couchdb/couch_httpd.erl | 4 +++- src/couchdb/couch_httpd_rewrite.erl | 19 +++++++------------ 3 files changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/couchdb/couch_db.hrl b/src/couchdb/couch_db.hrl index 47e8f9eb..f74bade7 100644 --- a/src/couchdb/couch_db.hrl +++ b/src/couchdb/couch_db.hrl @@ -73,7 +73,9 @@ user_ctx, req_body = undefined, design_url_handlers, - auth + auth, + default_fun, + url_handlers }). diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 6d0230f9..62616007 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -175,7 +175,9 @@ handle_request(MochiReq, DefaultFun, path_parts = [list_to_binary(couch_httpd:unquote(Part)) || Part <- string:tokens(Path, "/")], db_url_handlers = DbUrlHandlers, - design_url_handlers = DesignUrlHandlers + design_url_handlers = DesignUrlHandlers, + default_fun = DefaultFun, + url_handlers = UrlHandlers }, HandlerFun = couch_util:dict_find(HandlerKey, UrlHandlers, DefaultFun), diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl index eabe98df..72ec9545 100644 --- a/src/couchdb/couch_httpd_rewrite.erl +++ b/src/couchdb/couch_httpd_rewrite.erl @@ -172,20 +172,15 @@ handle_rewrite_req(#httpd{ % cleanup, It force mochiweb to reparse raw uri. MochiReq1:cleanup(), - DefaultSpec = "{couch_httpd_db, handle_request}", - DefaultFun = couch_httpd:make_arity_1_fun( - couch_config:get("httpd", "default_handler", DefaultSpec) - ), - - UrlHandlersList = lists:map( - fun({UrlKey, SpecStr}) -> - {?l2b(UrlKey), couch_httpd:make_arity_1_fun(SpecStr)} - end, couch_config:get("httpd_global_handlers")), - UrlHandlers = dict:from_list(UrlHandlersList), + #httpd{ + db_url_handlers = DbUrlHandlers, + design_url_handlers = DesignUrlHandlers, + default_fun = DefaultFun, + url_handlers = UrlHandlers + } = Req, couch_httpd:handle_request(MochiReq1, DefaultFun, - UrlHandlers, Req#httpd.db_url_handlers, - Req#httpd.design_url_handlers) + UrlHandlers, DbUrlHandlers, DesignUrlHandlers) end. -- cgit v1.2.3