summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_httpd.erl34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 61bdc177..8da157b3 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -173,20 +173,11 @@ handle_request(MochiReq, DefaultFun,
{ok, Resp} =
try
- % Try authentication handlers in order until one returns a result
- case lists:foldl(fun(_Fun, #httpd{user_ctx=#user_ctx{}}=Req) -> Req;
- (Fun, #httpd{}=Req) -> Fun(Req);
- (_Fun, Response) -> Response
- end, HttpReq, AuthenticationFuns) of
- #httpd{user_ctx=#user_ctx{}}=Req -> HandlerFun(Req);
- #httpd{}=Req ->
- case couch_config:get("couch_httpd_auth", "require_valid_user", "false") of
- "true" ->
- throw({unauthorized, <<"Authentication required.">>});
- _ ->
- HandlerFun(Req#httpd{user_ctx=#user_ctx{}})
- end;
- Response -> Response
+ case authenticate_request(HttpReq, AuthenticationFuns) of
+ Req when is_record(Req, httpd) ->
+ HandlerFun(Req);
+ Response ->
+ Response
end
catch
throw:Error ->
@@ -218,6 +209,21 @@ handle_request(MochiReq, DefaultFun,
couch_stats_collector:increment({httpd, requests}),
{ok, Resp}.
+% Try authentication handlers in order until one returns a result
+authenticate_request(#httpd{user_ctx=#user_ctx{}} = Req, _AuthFuns) ->
+ Req;
+authenticate_request(#httpd{} = Req, []) ->
+ case couch_config:get("couch_httpd_auth", "require_valid_user", "false") of
+ "true" ->
+ throw({unauthorized, <<"Authentication required.">>});
+ "false" ->
+ Req#httpd{user_ctx=#user_ctx{}}
+ end;
+authenticate_request(#httpd{} = Req, [AuthFun|Rest]) ->
+ authenticate_request(AuthFun(Req), Rest);
+authenticate_request(Response, _AuthFuns) ->
+ Response.
+
increment_method_stats(Method) ->
couch_stats_collector:increment({httpd_request_methods, Method}).