You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2012/11/12 18:56:35 UTC

git commit: move commonly sued functions to the utils part of the file

Updated Branches:
  refs/heads/431-feature_cors 164214567 -> ea7186d01


move commonly sued functions to the utils part of the file


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

Branch: refs/heads/431-feature_cors
Commit: ea7186d013c769827d9f5a3e4fcb156080e205b4
Parents: 1642145
Author: Jan Lehnardt <ja...@apache.org>
Authored: Mon Nov 12 18:56:08 2012 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Mon Nov 12 18:56:08 2012 +0100

----------------------------------------------------------------------
 src/couchdb/couch_httpd_cors.erl |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/ea7186d0/src/couchdb/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index d524038..17f634a 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -171,22 +171,6 @@ send_preflight_response(#httpd{mochi_req=MochiReq}=Req, Headers) ->
     {ok, MochiReq:respond({204, Headers2, <<>>})}.
 
 
-maybe_add_credentials(Origin, Host, Headers) ->
-    maybe_add_credentials(Headers, credentials(Origin, Host)).
-
-maybe_add_credentials(Headers, false) ->
-    Headers;
-maybe_add_credentials(Headers, true) ->
-    Headers ++ [{"Access-Control-Allow-Credentials", "true"}].
-
-
-credentials("*", _Host) ->
-    false;
-credentials(_Origin, Host) ->
-    Default = get_bool_config("cors", "credentials", false),
-    get_bool_config(cors_section(Host), "credentials", Default).
-
-
 % cors_headers/1
 
 cors_headers(MochiReq) ->
@@ -237,6 +221,23 @@ make_cors_header(Origin, Host) ->
 
 %% util
 
+maybe_add_credentials(Origin, Host, Headers) ->
+    maybe_add_credentials(Headers, allow_credentials(Origin, Host)).
+
+maybe_add_credentials(Headers, false) ->
+    Headers;
+maybe_add_credentials(Headers, true) ->
+    Headers ++ [{"Access-Control-Allow-Credentials", "true"}].
+
+
+allow_credentials("*", _Host) ->
+    false;
+allow_credentials(_Origin, Host) ->
+    Default = get_bool_config("cors", "credentials", false),
+    get_bool_config(cors_section(Host), "credentials", Default).
+
+
+
 cors_config(Host, Key, Default) ->
     couch_config:get(cors_section(Host), Key,
                      couch_config:get("cors", Key, Default)).