couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [2/3] git commit: move cookie value extraction into separate function
Date Mon, 19 Nov 2012 16:05:01 GMT
move cookie value extraction into separate function


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/a27b1413
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/a27b1413
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/a27b1413

Branch: refs/heads/test-for-unexported-functions
Commit: a27b1413a9f91d11c9c12781e64a076f258c5c55
Parents: 9a805b1
Author: Jan Lehnardt <jan@apache.org>
Authored: Mon Nov 19 16:59:10 2012 +0100
Committer: Jan Lehnardt <jan@apache.org>
Committed: Mon Nov 19 17:03:51 2012 +0100

----------------------------------------------------------------------
 src/couchdb/couch_httpd_auth.erl |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/a27b1413/src/couchdb/couch_httpd_auth.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl
index a967e09..7a8a94a 100644
--- a/src/couchdb/couch_httpd_auth.erl
+++ b/src/couchdb/couch_httpd_auth.erl
@@ -151,21 +151,23 @@ proxy_auth_user(Req) ->
             end
     end.
 
+decode_auth_session(Cookie) ->
+    try
+    AuthSession = couch_util:decodeBase64Url(Cookie),
+    [_A, _B, _Cs] = re:split(?b2l(AuthSession), ":",
+                             [{return, list}, {parts, 3}])
+    catch
+    _:_Error ->
+        Reason = <<"Malformed AuthSession cookie. Please clear your cookies.">>,
+        throw({bad_request, Reason})
+    end.
 
 cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req) ->
     case MochiReq:get_cookie_value("AuthSession") of
     undefined -> Req;
     [] -> Req;
     Cookie ->
-        [User, TimeStr, HashStr] = try
-            AuthSession = couch_util:decodeBase64Url(Cookie),
-            [_A, _B, _Cs] = re:split(?b2l(AuthSession), ":",
-                                     [{return, list}, {parts, 3}])
-        catch
-            _:_Error ->
-                Reason = <<"Malformed AuthSession cookie. Please clear your cookies.">>,
-                throw({bad_request, Reason})
-        end,
+        [User, TimeStr, HashStr] = decode_auth_session(Cookie),
         % Verify expiry and hash
         CurrentTime = make_cookie_time(),
         case couch_config:get("couch_httpd_auth", "secret", nil) of


Mime
View raw message