couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r805551 - /couchdb/trunk/src/couchdb/couch_httpd.erl
Date Tue, 18 Aug 2009 19:47:41 GMT
Author: kocolosk
Date: Tue Aug 18 19:47:41 2009
New Revision: 805551

URL: http://svn.apache.org/viewvc?rev=805551&view=rev
Log:
cleanup application of auth functions

Modified:
    couchdb/trunk/src/couchdb/couch_httpd.erl

Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=805551&r1=805550&r2=805551&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Tue Aug 18 19:47:41 2009
@@ -173,20 +173,11 @@
 
     {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 @@
     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}).
 



Mime
View raw message