summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/couchdb/couch_httpd_vhost.erl15
-rwxr-xr-xtest/etap/160-vhosts.t30
2 files changed, 23 insertions, 22 deletions
diff --git a/src/couchdb/couch_httpd_vhost.erl b/src/couchdb/couch_httpd_vhost.erl
index 3dba2919..9bfb5951 100644
--- a/src/couchdb/couch_httpd_vhost.erl
+++ b/src/couchdb/couch_httpd_vhost.erl
@@ -301,6 +301,7 @@ make_target([P|Rest], Bindings, Remaining, Acc) ->
%% bind port
bind_port(Port, Port) -> ok;
+bind_port('*', _) -> ok;
bind_port(_,_) -> fail.
%% bind bhost
@@ -329,15 +330,15 @@ bind_path(_, _) ->
%% create vhost list from ini
make_vhosts() ->
- lists:foldl(fun({Vhost, Path}, Acc) ->
- [{parse_vhost(Vhost), split_path(Path)}|Acc]
- end, [], couch_config:get("vhosts")).
-
+ Vhosts = lists:foldl(fun({Vhost, Path}, Acc) ->
+ [{parse_vhost(Vhost), split_path(Path)}|Acc]
+ end, [], couch_config:get("vhosts")),
+ lists:reverse(lists:usort(Vhosts)).
parse_vhost(Vhost) ->
case urlsplit_netloc(Vhost, []) of
{[], Path} ->
- {make_spec("*", []), 80, Path};
+ {make_spec("*", []), '*', Path};
{HostPort, []} ->
{H, P} = split_host_port(HostPort),
H1 = make_spec(H, []),
@@ -352,13 +353,13 @@ parse_vhost(Vhost) ->
split_host_port(HostAsString) ->
case string:rchr(HostAsString, $:) of
0 ->
- {split_host(HostAsString), 80};
+ {split_host(HostAsString), '*'};
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};
+ {split_host(HostAsString), '*'};
Port ->
{split_host(HostPart), Port}
end
diff --git a/test/etap/160-vhosts.t b/test/etap/160-vhosts.t
index c7dc8f99..8dac53e5 100755
--- a/test/etap/160-vhosts.t
+++ b/test/etap/160-vhosts.t
@@ -155,9 +155,9 @@ test_regular_request() ->
test_vhost_request() ->
case ibrowse:send_req(server(), [], get, [], [{host_header, "example.com"}]) of
{ok, _, _, Body} ->
- {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
- = couch_util:json_decode(Body),
- etap:is(true, true, "should return database info");
+ {JsonBody} = couch_util:json_decode(Body),
+ HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
+ etap:is(HasDbNameInfo, true, "should return database info");
_Else ->
etap:is(false, true, <<"ibrowse fail">>)
end.
@@ -222,9 +222,9 @@ test_vhost_request_wildcard()->
test_vhost_request_replace_var() ->
case ibrowse:send_req(server(), [], get, [], [{host_header,"etap-test-db.example1.com"}]) of
{ok, _, _, Body} ->
- {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
- = couch_util:json_decode(Body),
- etap:is(true, true, "should return database info");
+ {JsonBody} = couch_util:json_decode(Body),
+ HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
+ etap:is(HasDbNameInfo, true, "should return database info");
_Else -> etap:is(false, true, <<"ibrowse fail">>)
end.
@@ -242,9 +242,9 @@ test_vhost_request_replace_var1() ->
test_vhost_request_replace_wildcard() ->
case ibrowse:send_req(server(), [], get, [], [{host_header,"etap-test-db.example2.com"}]) of
{ok, _, _, Body} ->
- {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
- = couch_util:json_decode(Body),
- etap:is(true, true, "should return database info");
+ {JsonBody} = couch_util:json_decode(Body),
+ HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
+ etap:is(HasDbNameInfo, true, "should return database info");
_Else -> etap:is(false, true, <<"ibrowse fail">>)
end.
@@ -252,9 +252,9 @@ test_vhost_request_path() ->
Uri = server() ++ "test",
case ibrowse:send_req(Uri, [], get, [], [{host_header, "example.com"}]) of
{ok, _, _, Body} ->
- {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
- = couch_util:json_decode(Body),
- etap:is(true, true, "should return database info");
+ {JsonBody} = couch_util:json_decode(Body),
+ HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
+ etap:is(HasDbNameInfo, true, "should return database info");
_Else -> etap:is(false, true, <<"ibrowse fail">>)
end.
@@ -272,9 +272,9 @@ test_vhost_request_path2() ->
Uri = server() ++ "test",
case ibrowse:send_req(Uri, [], get, [], [{host_header,"etap-test-db.example2.com"}]) of
{ok, _, _, Body} ->
- {[{<<"db_name">>, <<"etap-test-db">>},_,_,_,_,_,_,_,_,_]}
- = couch_util:json_decode(Body),
- etap:is(true, true, "should return database info");
+ {JsonBody} = couch_util:json_decode(Body),
+ HasDbNameInfo = proplists:is_defined(<<"db_name">>, JsonBody),
+ etap:is(HasDbNameInfo, true, "should return database info");
_Else -> etap:is(false, true, <<"ibrowse fail">>)
end.