summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoan Touzet <joant@atypical.net>2019-10-14 16:42:26 +0100
committerRobert Newson <rnewson@apache.org>2019-12-02 17:51:44 +0000
commit1f0e8cf983da96df22740e84f6fbd58b2711719a (patch)
tree0e4260d836b1b0f1abf4aefbcfae17296d57cb61
parent312cdeeae26d1be483002ab3bd15a2b0551aae2c (diff)
downloadcouchdb-1f0e8cf983da96df22740e84f6fbd58b2711719a.tar.gz
extract get_httpd_handlers function
-rw-r--r--src/couch/src/couch_httpd.erl58
1 files changed, 30 insertions, 28 deletions
diff --git a/src/couch/src/couch_httpd.erl b/src/couch/src/couch_httpd.erl
index 10b44d16d..1085a5b58 100644
--- a/src/couch/src/couch_httpd.erl
+++ b/src/couch/src/couch_httpd.erl
@@ -104,38 +104,14 @@ start_link(Name, Options) ->
Else -> Else
end,
ok = validate_bind_address(BindAddress),
- DefaultFun = make_arity_1_fun("{couch_httpd_db, handle_request}"),
-
- {ok, HttpdGlobalHandlers} = application:get_env(httpd_global_handlers),
-
- UrlHandlersList = lists:map(
- fun({UrlKey, SpecStr}) ->
- {?l2b(UrlKey), make_arity_1_fun(SpecStr)}
- end, HttpdGlobalHandlers),
-
- {ok, HttpdDbHandlers} = application:get_env(httpd_db_handlers),
-
- DbUrlHandlersList = lists:map(
- fun({UrlKey, SpecStr}) ->
- {?l2b(UrlKey), make_arity_2_fun(SpecStr)}
- end, HttpdDbHandlers),
-
- {ok, HttpdDesignHandlers} = application:get_env(httpd_design_handlers),
- DesignUrlHandlersList = lists:map(
- fun({UrlKey, SpecStr}) ->
- {?l2b(UrlKey), make_arity_3_fun(SpecStr)}
- end, HttpdDesignHandlers),
-
- UrlHandlers = dict:from_list(UrlHandlersList),
- DbUrlHandlers = dict:from_list(DbUrlHandlersList),
- DesignUrlHandlers = dict:from_list(DesignUrlHandlersList),
{ok, ServerOptions} = couch_util:parse_term(
config:get("httpd", "server_options", "[]")),
{ok, SocketOptions} = couch_util:parse_term(
config:get("httpd", "socket_options", "[]")),
set_auth_handlers(),
+ Handlers = get_httpd_handlers(),
% ensure uuid is set so that concurrent replications
% get the same value.
@@ -148,9 +124,7 @@ start_link(Name, Options) ->
_ ->
ok = mochiweb_socket:setopts(Req:get(socket), SocketOptions)
end,
- apply(?MODULE, handle_request, [
- Req, DefaultFun, UrlHandlers, DbUrlHandlers, DesignUrlHandlers
- ])
+ apply(?MODULE, handle_request, [Req | Handlers])
end,
% set mochiweb options
@@ -187,6 +161,34 @@ set_auth_handlers() ->
auth_handler_name(SpecStr) ->
lists:nth(?HANDLER_NAME_IN_MODULE_POS, re:split(SpecStr, "[\\W_]", [])).
+get_httpd_handlers() ->
+ {ok, HttpdGlobalHandlers} = application:get_env(httpd_global_handlers),
+
+ UrlHandlersList = lists:map(
+ fun({UrlKey, SpecStr}) ->
+ {?l2b(UrlKey), make_arity_1_fun(SpecStr)}
+ end, HttpdGlobalHandlers),
+
+ {ok, HttpdDbHandlers} = application:get_env(httpd_db_handlers),
+
+ DbUrlHandlersList = lists:map(
+ fun({UrlKey, SpecStr}) ->
+ {?l2b(UrlKey), make_arity_2_fun(SpecStr)}
+ end, HttpdDbHandlers),
+
+ {ok, HttpdDesignHandlers} = application:get_env(httpd_design_handlers),
+
+ DesignUrlHandlersList = lists:map(
+ fun({UrlKey, SpecStr}) ->
+ {?l2b(UrlKey), make_arity_3_fun(SpecStr)}
+ end, HttpdDesignHandlers),
+
+ UrlHandlers = dict:from_list(UrlHandlersList),
+ DbUrlHandlers = dict:from_list(DbUrlHandlersList),
+ DesignUrlHandlers = dict:from_list(DesignUrlHandlersList),
+ DefaultFun = make_arity_1_fun("{couch_httpd_db, handle_request}"),
+ [DefaultFun, UrlHandlers, DbUrlHandlers, DesignUrlHandlers].
+
% SpecStr is a string like "{my_module, my_fun}"
% or "{my_module, my_fun, <<"my_arg">>}"
make_arity_1_fun(SpecStr) ->