diff options
-rw-r--r-- | src/couchdb/couch_httpd_vhost.erl | 26 | ||||
-rwxr-xr-x | test/etap/160-vhosts.t | 6 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/couchdb/couch_httpd_vhost.erl b/src/couchdb/couch_httpd_vhost.erl index 318a0fe2..06bb95c2 100644 --- a/src/couchdb/couch_httpd_vhost.erl +++ b/src/couchdb/couch_httpd_vhost.erl @@ -63,8 +63,8 @@ %% %% [vhosts] %% *.example.com = /* -%% $dbname.example.com = /$dbname -%% $ddocname.$dbname.example.com = /$dbname/_design/$ddocname/_rewrite +%% :dbname.example.com = /:dbname +%% :ddocname.:dbname.example.com = /:dbname/_design/:ddocname/_rewrite %% %% First rule pass wildcard as dbname, second do the same but use a %% variable name and the third one allows you to use any app with @@ -312,14 +312,18 @@ make_vhosts() -> split_host_port(HostAsString) -> - case string:tokens(HostAsString, ":") of - [HostPart, PortPart] -> - {split_host(HostPart), list_to_integer(PortPart)}; - [HostPart] -> - {split_host(HostPart), 80}; - [] -> - %% no host header - {[], 80} + case string:rchr(HostAsString, $:) of + 0 -> + {split_host(HostAsString), 80}; + N -> + HostPart = string:substr(HostAsString, 1, N-1), + case (catch erlang:list_to_integer(HostAsString, N+1, + length(HostAsString))) of + {'EXIT', _} -> + {split_host(HostAsString), 80}; + Port -> + {split_host(HostPart), Port} + end end. split_host(HostAsString) -> @@ -342,7 +346,7 @@ make_spec([P|R], Acc) -> parse_var(P) -> case P of - "$" ++ Var -> + ":" ++ Var -> {bind, Var}; _ -> P end. diff --git a/test/etap/160-vhosts.t b/test/etap/160-vhosts.t index b1050d7f..7eaf2874 100755 --- a/test/etap/160-vhosts.t +++ b/test/etap/160-vhosts.t @@ -107,9 +107,9 @@ test() -> "/etap-test-db/_design/doc1/_rewrite", false), ok = couch_config:set("vhosts", "example1.com", "/etap-test-db/_design/doc1/_rewrite/", false), - ok = couch_config:set("vhosts","$appname.$dbname.example1.com", - "/$dbname/_design/$appname/_rewrite/", false), - ok = couch_config:set("vhosts", "$dbname.example1.com", "/$dbname", false), + ok = couch_config:set("vhosts",":appname.:dbname.example1.com", + "/:dbname/_design/:appname/_rewrite/", false), + ok = couch_config:set("vhosts", ":dbname.example1.com", "/:dbname", false), ok = couch_config:set("vhosts", "*.example2.com", "/*", false), |