summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2009-08-18 19:47:41 +0000
committerAdam Kocoloski <kocolosk@apache.org>2009-08-18 19:47:41 +0000
commit86bb26326e0bcc09e058d56d67dd124c5e3ecee5 (patch)
treef52da5cc2b94149a03237ddd465912d0edba3ffe /src
parent0a902eb4ad64ee86f8af9915efb26a46bbb84d50 (diff)
cleanup application of auth functions
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@805551 13f79535-47bb-0310-9956-ffa450edef68
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}).