From 839434c722b90b9e3681f77483538127dc0c09fd Mon Sep 17 00:00:00 2001 From: Paul Joseph Davis Date: Wed, 20 May 2009 13:06:50 +0000 Subject: Move default handler configuration to couch_httpd:start_link/0 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@776685 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd.erl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/couchdb') diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 8cdc8733..34a13c88 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -13,7 +13,7 @@ -module(couch_httpd). -include("couch_db.hrl"). --export([start_link/0, stop/0, handle_request/4]). +-export([start_link/0, stop/0, handle_request/5]). -export([header_value/2,header_value/3,qs_value/2,qs_value/3,qs/1,path/1,absolute_uri/2]). -export([verify_is_server_admin/1,unquote/1,quote/1,recv/2,recv_chunked/4,error_info/1]). @@ -35,6 +35,11 @@ start_link() -> BindAddress = couch_config:get("httpd", "bind_address", any), Port = couch_config:get("httpd", "port", "5984"), + DefaultSpec = "{couch_httpd_db, handle_request}", + DefaultFun = make_arity_1_fun( + couch_config:get("httpd", "default_handler", DefaultSpec) + ), + UrlHandlersList = lists:map( fun({UrlKey, SpecStr}) -> {?l2b(UrlKey), make_arity_1_fun(SpecStr)} @@ -49,14 +54,15 @@ start_link() -> fun({UrlKey, SpecStr}) -> {?l2b(UrlKey), make_arity_2_fun(SpecStr)} end, couch_config:get("httpd_design_handlers")), - + UrlHandlers = dict:from_list(UrlHandlersList), DbUrlHandlers = dict:from_list(DbUrlHandlersList), DesignUrlHandlers = dict:from_list(DesignUrlHandlersList), Loop = fun(Req)-> - apply(?MODULE, handle_request, - [Req, UrlHandlers, DbUrlHandlers, DesignUrlHandlers]) - end, + apply(?MODULE, handle_request, [ + Req, DefaultFun, UrlHandlers, DbUrlHandlers, DesignUrlHandlers + ]) + end, % and off we go @@ -77,6 +83,8 @@ start_link() -> ?MODULE:stop(); ("httpd", "port") -> ?MODULE:stop(); + ("httpd", "default_handler") -> + ?MODULE:stop(); ("httpd_global_handlers", _) -> ?MODULE:stop(); ("httpd_db_handlers", _) -> @@ -108,7 +116,8 @@ stop() -> mochiweb_http:stop(?MODULE). -handle_request(MochiReq, UrlHandlers, DbUrlHandlers, DesignUrlHandlers) -> +handle_request(MochiReq, DefaultFun, + UrlHandlers, DbUrlHandlers, DesignUrlHandlers) -> Begin = now(), AuthenticationFun = make_arity_1_fun( couch_config:get("httpd", "authentication_handler")), @@ -158,16 +167,7 @@ handle_request(MochiReq, UrlHandlers, DbUrlHandlers, DesignUrlHandlers) -> design_url_handlers = DesignUrlHandlers }, - DefaultSpec = "{couch_httpd_db, handle_request}", - DefaultFun = make_arity_1_fun( - couch_config:get("httpd", "default_handler", DefaultSpec) - ), HandlerFun = couch_util:dict_find(HandlerKey, UrlHandlers, DefaultFun), - - Self = self(), - ok = couch_config:register( - fun("httpd", "default_handler") -> exit(Self, config_change) end - ), {ok, Resp} = try -- cgit v1.2.3