couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [22/44] git commit: refactor cors_headers() for clarity
Date Tue, 04 Dec 2012 20:43:49 GMT
refactor cors_headers() for clarity


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

Branch: refs/heads/1368-fix-multipart-header-parts
Commit: e8b53346ee13662bb214267ee128fa6f4993cc82
Parents: f976cfe
Author: Jan Lehnardt <jan@apache.org>
Authored: Thu Nov 8 22:22:41 2012 +0100
Committer: Jan Lehnardt <jan@apache.org>
Committed: Thu Nov 8 23:37:34 2012 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb/blob/e8b53346/src/couchdb/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index a783ae6..2a391ae 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -33,7 +33,7 @@
 is_preflight_request(#httpd{method=Method}=Req) when Method /= 'OPTIONS' ->
     Req;
 is_preflight_request(Req) ->
-    EnableCors = get_bool_config("httpd", "enable_cors", false),
+    EnableCors = enable_cors(),
     is_preflight_request(Req, EnableCors).
 
 is_preflight_request(Req, false) ->
@@ -46,21 +46,22 @@ is_preflight_request(#httpd{mochi_req=MochiReq}=Req, true) ->
             Req
     end.
 
-cors_headers(#httpd{mochi_req=MochiReq}) ->
+cors_headers(MochiReq) ->
+    EnableCors = enable_cors(),
+    cors_headers(MochiReq, EnableCors).
+
+cors_headers(#httpd{mochi_req=MochiReq}, true) ->
     Host = couch_httpd_vhost:host(MochiReq),
-    case get_bool_config("httpd", "enable_cors", false) of
-        true ->
-            AcceptedOrigins = split_list(cors_config(Host, "origins", [])),
-            case MochiReq:get_header_value("Origin") of
-                undefined ->
-                    [];
-                Origin ->
-                    handle_cors_headers(couch_util:to_list(Origin),
-                                        Host, AcceptedOrigins)
-            end;
-        false ->
-            []
-    end.
+    AcceptedOrigins = split_list(cors_config(Host, "origins", [])),
+    case MochiReq:get_header_value("Origin") of
+        undefined ->
+            [];
+        Origin ->
+            handle_cors_headers(couch_util:to_list(Origin),
+                                Host, AcceptedOrigins)
+    end;
+cors_headers(_MochiReq, false) ->
+    [].
 
 handle_cors_headers(_Origin, _Host, []) ->
     [];
@@ -199,6 +200,9 @@ cors_section(Host0) ->
     {Host, _Port} = split_host_port(Host0),
     "cors:" ++ Host.
 
+enable_cors() ->
+    get_bool_config("httpd", "enable_cors", false).
+
 get_bool_config(Section, Key, Default) ->
     case couch_config:get(Section, Key) of
         undefined ->


Mime
View raw message