couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [3/28] git commit: simplify `preflight_request()`
Date Sun, 11 Nov 2012 19:24:31 GMT
simplify `preflight_request()`


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

Branch: refs/heads/431-feature-cors
Commit: 2995c20da26559f9bf3b03feb36f3f08ed35290c
Parents: 1191c8c
Author: Jan Lehnardt <jan@apache.org>
Authored: Sun Nov 11 15:56:22 2012 +0000
Committer: Jan Lehnardt <jan@apache.org>
Committed: Sun Nov 11 16:11:16 2012 +0000

----------------------------------------------------------------------
 src/couchdb/couch_httpd_cors.erl |   42 ++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/2995c20d/src/couchdb/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index 90a7543..7e45c96 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -85,30 +85,34 @@ make_cors_header(Origin, Host) ->
     maybe_add_credentials(Origin, Host, Headers).
 
 preflight_request(MochiReq) ->
+    Origin = MochiReq:get_header_value("Origin"),
+    preflight_request(MochiReq, Origin).
+
+preflight_request(MochiReq, undefined) ->
+    MochiReq;
+preflight_request(MochiReq, Origin) ->
     Host = couch_httpd_vhost:host(MochiReq),
-    case MochiReq:get_header_value("Origin") of
-    undefined ->
-        MochiReq;
+    AcceptedOrigins = get_accepted_origins(Host),
+    AcceptAll = lists:member("*", AcceptedOrigins),
 
-    Origin ->
-        AcceptedOrigins = get_accepted_origins(Host),
-        AcceptAll = lists:member("*", AcceptedOrigins),
-
-        case {AcceptAll, AcceptedOrigins} of
-        {true, _} ->
-            handle_preflight_request(couch_util:to_list(Origin),
-                                     Host, MochiReq);
-        {false, _} ->
-            case lists:member(Origin, AcceptedOrigins) of
-            true ->
-                handle_preflight_request(couch_util:to_list(Origin),
-                                         Host, MochiReq);
-            false ->
-                false
-            end
+    HandlerFun = fun() ->
+        OriginList = couch_util:to_list(Origin),
+        handle_preflight_request(OriginList, Host, MochiReq)
+    end,
+
+    case AcceptAll of
+    true ->
+        HandlerFun();
+    false ->
+        case lists:member(Origin, AcceptedOrigins) of
+        true ->
+            HandlerFun();
+        false ->
+            false
         end
     end.
 
+
 handle_preflight_request(Origin, Host, MochiReq) ->
     %% get supported methods
     SupportedMethods = split_list(cors_config(Host, "methods",


Mime
View raw message