couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iil...@apache.org
Subject [35/50] couch-httpd commit: updated refs/heads/split_out_httpd_stack to e44a372
Date Tue, 01 Mar 2016 20:01:08 GMT
Strip scheme out of Host for cors_section

Value returned by `couch_httpd_vhost:host/1` might not contain scheme.
The cors section is named after vhost name (i.e. without scheme).
For example:

    [cors:partner.com]
    methods =
    headers =
    exposed_headers =
    origins = http://restricted.dev:8000

The origin in origins has to be given with scheme included.

COUCHDB-2945


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

Branch: refs/heads/split_out_httpd_stack
Commit: 8419546777985d3aa52479f2f687c237da71aa93
Parents: cfbd7f7
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Tue Feb 16 15:23:37 2016 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Mar 1 08:35:09 2016 -0800

----------------------------------------------------------------------
 src/couch_httpd_cors.erl | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/84195467/src/couch_httpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_cors.erl b/src/couch_httpd_cors.erl
index 401ad2e..8c47c7a 100644
--- a/src/couch_httpd_cors.erl
+++ b/src/couch_httpd_cors.erl
@@ -320,30 +320,17 @@ cors_config(Host, Key, Default) ->
     config:get(cors_section(Host), Key,
                      config:get("cors", Key, Default)).
 
-cors_section(Host0) ->
-    {Host, _Port} = split_host_port(Host0),
+cors_section(HostValue) ->
+    HostPort = maybe_strip_scheme(HostValue),
+    Host = hd(string:tokens(HostPort, ":")),
     "cors:" ++ Host.
 
-split_host_port(HostAsString) ->
-    % split at semicolon ":"
-    Split = string:rchr(HostAsString, $:),
-    split_host_port(HostAsString, Split).
-
-split_host_port(HostAsString, 0) ->
-    % no semicolon
-    {HostAsString, '*'};
-split_host_port(HostAsString, N) ->
-    HostPart = string:substr(HostAsString, 1, N-1),
-    % parse out port
-    % is there a nicer way?
-    case (catch erlang:list_to_integer(string:substr(HostAsString,
-                    N+1, length(HostAsString)))) of
-    {'EXIT', _} ->
-        {HostAsString, '*'};
-    Port ->
-        {HostPart, Port}
-    end.
 
+maybe_strip_scheme(Host) ->
+    case string:str(Host, "://") of
+        0 -> Host;
+        N -> string:substr(Host, N + 3)
+    end.
 
 is_cors_enabled(Config) ->
     case get(disable_couch_httpd_cors) of


Mime
View raw message