diff options
| author | Benoit Chesneau <benoitc@apache.org> | 2010-08-20 06:22:41 +0000 | 
|---|---|---|
| committer | Benoit Chesneau <benoitc@apache.org> | 2010-08-20 06:22:41 +0000 | 
| commit | 04d3501301031fde6bce119a8c9275ef9e8830d5 (patch) | |
| tree | 20b22c8daf46ff390cfb3ad5b08afb5d30106d29 | |
| parent | e8e814755df487f16afbd22ec59d6c69c39f7c99 (diff) | |
sysadmins were shocked that we can use $ for anything else than a shell
environment variable. use ":" instead. use ":" instead like we do in
_rewrite handler. like we do in _rewrite handler.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@987384 13f79535-47bb-0310-9956-ffa450edef68
| -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), | 
