couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [15/28] git commit: Simplify code:
Date Sun, 11 Nov 2012 19:24:31 GMT
Simplify code:

 - turn two more instances of split_list/1 into a function call
 - add split_header/1 to make code more readable in a tricky section


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

Branch: refs/heads/431-feature-cors
Commit: d6bda4849a0926a43bb6b837d0648c9a95164d23
Parents: fcb9bfb
Author: Jan Lehnardt <jan@apache.org>
Authored: Thu Nov 8 22:14:11 2012 +0100
Committer: Jan Lehnardt <jan@apache.org>
Committed: Sun Nov 11 16:11:15 2012 +0000

----------------------------------------------------------------------
 src/couchdb/couch_httpd_cors.erl |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/d6bda484/src/couchdb/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_cors.erl b/src/couchdb/couch_httpd_cors.erl
index ef01ef4..6f501cc 100644
--- a/src/couchdb/couch_httpd_cors.erl
+++ b/src/couchdb/couch_httpd_cors.erl
@@ -50,9 +50,7 @@ cors_headers(#httpd{mochi_req=MochiReq}) ->
     Host = couch_httpd_vhost:host(MochiReq),
     case get_bool_config("httpd", "enable_cors", false) of
         true ->
-            AcceptedOrigins = re:split(cors_config(Host, "origins", []),
-                                       "\\s*,\\s*",
-                                       [trim, {return, list}]),
+            AcceptedOrigins = split_list(cors_config(Host, "origins", [])),
             case MochiReq:get_header_value("Origin") of
                 undefined ->
                     [];
@@ -93,9 +91,7 @@ preflight_request(MochiReq) ->
             MochiReq;
 
         Origin ->
-            AcceptedOrigins = re:split(cors_config(Host, "origins", []),
-                                       "\\s*,\\s*",
-                                       [trim, {return, list}]),
+            AcceptedOrigins = split_list(cors_config(Host, "origins", [])),
             AcceptAll = lists:member("*", AcceptedOrigins),
 
             case {AcceptAll, AcceptedOrigins} of
@@ -157,8 +153,7 @@ handle_preflight_request(Origin, Host, MochiReq) ->
                             % could check. make sure everything is a
                             % list
                             RH = [string:to_lower(H)
-                                  || H <- re:split(Headers, ",\\s*",
-                                                   [{return,list},trim])],
+                                  || H <- split_headers(Headers)],
                             {Headers, RH}
                     end,
                     % check if headers are supported
@@ -217,6 +212,9 @@ get_bool_config(Section, Key, Default) ->
 split_list(S) ->
     re:split(S, "\\s*,\\s*", [trim, {return, list}]).
 
+split_headers(H) ->
+    re:split(H, ",\\s*", [{return,list}, trim]).
+
 split_host_port(HostAsString) ->
     case string:rchr(HostAsString, $:) of
         0 ->


Mime
View raw message