couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [5/5] git commit: reorder functions by exported function they support
Date Sun, 11 Nov 2012 19:32:04 GMT
reorder functions by exported function they support


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

Branch: refs/heads/431-feature_cors
Commit: bcdac76ca5a71898054a8a9b3b1c05af5892cdd3
Parents: 31a8268
Author: Jan Lehnardt <jan@apache.org>
Authored: Sun Nov 11 16:19:03 2012 +0000
Committer: Jan Lehnardt <jan@apache.org>
Committed: Sun Nov 11 20:32:02 2012 +0100

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


http://git-wip-us.apache.org/repos/asf/couchdb/blob/bcdac76c/src/couchdb/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index 14b93f4..053adf0 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -33,6 +33,8 @@
 % TODO: - pick a sane default
 -define(CORS_DEFAULT_MAX_AGE, 12345).
 
+%% is_preflight_request/1
+
 is_preflight_request(#httpd{method=Method}=Req) when Method /= 'OPTIONS' ->
     Req;
 is_preflight_request(Req) ->
@@ -49,40 +51,6 @@ is_preflight_request(#httpd{mochi_req=MochiReq}=Req, true) ->
         Req
     end.
 
-cors_headers(MochiReq) ->
-    EnableCors = enable_cors(),
-    cors_headers(MochiReq, EnableCors).
-
-cors_headers(#httpd{mochi_req=MochiReq}, true) ->
-    Host = couch_httpd_vhost:host(MochiReq),
-    AcceptedOrigins = get_accepted_origins(Host),
-    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, []) ->
-    [];
-handle_cors_headers(Origin, Host, AcceptedOrigins) ->
-    AcceptAll = lists:member("*", AcceptedOrigins),
-    case {AcceptAll, lists:member(Origin, AcceptedOrigins)} of
-    {true, _} ->
-        make_cors_header(Origin, Host);
-    {false, true}  ->
-        make_cors_header(Origin, Host);
-    _ ->
-        []
-    end.
-
-
-make_cors_header(Origin, Host) ->
-    Headers = [{"Access-Control-Allow-Origin", Origin}],
-    maybe_add_credentials(Origin, Host, Headers).
 
 preflight_request(MochiReq) ->
     Origin = MochiReq:get_header_value("Origin"),
@@ -193,6 +161,47 @@ credentials(_Origin, Host) ->
     get_bool_config(cors_section(Host), "credentials", Default).
 
 
+% cors_headers/1
+
+cors_headers(MochiReq) ->
+    EnableCors = enable_cors(),
+    cors_headers(MochiReq, EnableCors).
+
+cors_headers(#httpd{mochi_req=MochiReq}, true) ->
+    Host = couch_httpd_vhost:host(MochiReq),
+    AcceptedOrigins = get_accepted_origins(Host),
+    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, []) ->
+    [];
+handle_cors_headers(Origin, Host, AcceptedOrigins) ->
+    AcceptAll = lists:member("*", AcceptedOrigins),
+    case {AcceptAll, lists:member(Origin, AcceptedOrigins)} of
+    {true, _} ->
+        make_cors_header(Origin, Host);
+    {false, true}  ->
+        make_cors_header(Origin, Host);
+    _ ->
+        []
+    end.
+
+
+make_cors_header(Origin, Host) ->
+    Headers = [{"Access-Control-Allow-Origin", Origin}],
+    maybe_add_credentials(Origin, Host, Headers).
+
+
+%% util
+
 cors_config(Host, Key, Default) ->
     couch_config:get(cors_section(Host), Key,
                      couch_config:get("cors", Key, Default)).


Mime
View raw message