You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2016/03/03 21:06:08 UTC
[3/5] chttpd commit: updated refs/heads/master to ad754a3
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-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/5b7096dc
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/5b7096dc
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/5b7096dc
Branch: refs/heads/master
Commit: 5b7096dc1e908b4384aa16190b0469d1e15ef844
Parents: 1745808
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 16 15:23:37 2016 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Mar 3 11:58:49 2016 -0800
----------------------------------------------------------------------
src/chttpd_cors.erl | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/5b7096dc/src/chttpd_cors.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_cors.erl b/src/chttpd_cors.erl
index 0cb2061..dcbcad9 100644
--- a/src/chttpd_cors.erl
+++ b/src/chttpd_cors.erl
@@ -318,28 +318,16 @@ cors_config(Host, Key, Default) ->
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}
+
+maybe_strip_scheme(Host) ->
+ case string:str(Host, "://") of
+ 0 -> Host;
+ N -> string:substr(Host, N + 3)
end.