couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1142685 - in /couchdb/trunk: src/couchdb/couch_httpd_vhost.erl test/etap/160-vhosts.t
Date Mon, 04 Jul 2011 14:23:25 GMT
Author: jan
Date: Mon Jul  4 14:23:24 2011
New Revision: 1142685

URL: http://svn.apache.org/viewvc?rev=1142685&view=rev
Log:
Allow "/" as a vhost target.

Includes a single whitespace fix.

Modified:
    couchdb/trunk/src/couchdb/couch_httpd_vhost.erl
    couchdb/trunk/test/etap/160-vhosts.t

Modified: couchdb/trunk/src/couchdb/couch_httpd_vhost.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_vhost.erl?rev=1142685&r1=1142684&r2=1142685&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_vhost.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_vhost.erl Mon Jul  4 14:23:24 2011
@@ -127,11 +127,16 @@ dispatch_host(MochiReq) ->
             end
     end,
     FinalMochiReq.
-        
+
+append_path("/"=_Target, "/"=_Path) ->
+    "/";
+append_path(Target, Path) ->
+    Target ++ Path.
+
 % default redirect vhost handler 
 redirect_to_vhost(MochiReq, VhostTarget) ->
     Path = MochiReq:get(raw_path),
-    Target = VhostTarget ++ Path,
+    Target = append_path(VhostTarget, Path),
 
     ?LOG_DEBUG("Vhost Target: '~p'~n", [Target]),
 

Modified: couchdb/trunk/test/etap/160-vhosts.t
URL: http://svn.apache.org/viewvc/couchdb/trunk/test/etap/160-vhosts.t?rev=1142685&r1=1142684&r2=1142685&view=diff
==============================================================================
--- couchdb/trunk/test/etap/160-vhosts.t (original)
+++ couchdb/trunk/test/etap/160-vhosts.t Mon Jul  4 14:23:24 2011
@@ -52,7 +52,7 @@ admin_user_ctx() -> {user_ctx, #user_ctx
 main(_) ->
     test_util:init_code_path(),
 
-    etap:plan(14),
+    etap:plan(15),
     case (catch test()) of
         ok ->
             etap:end_tests();
@@ -115,6 +115,7 @@ test() ->
     ok = couch_config:set("vhosts", "*/test", "/etap-test-db", false), 
     ok = couch_config:set("vhosts", "*/test1", 
             "/etap-test-db/_design/doc1/_show/test", false), 
+    ok = couch_config:set("vhosts", "example3.com", "/", false),
 
     %% reload rules
     couch_httpd_vhost:reload(),
@@ -133,6 +134,7 @@ test() ->
     test_vhost_request_path1(),
     test_vhost_request_path2(),
     test_vhost_request_path3(),
+    test_vhost_request_to_root(),
 
     %% restart boilerplate
     couch_db:close(Db),
@@ -289,3 +291,13 @@ test_vhost_request_path3() ->
             end, true, <<"path in req ok">>);
         _Else -> etap:is(false, true, <<"ibrowse fail">>)
     end.
+
+test_vhost_request_to_root() ->
+    Uri = server(),
+    case ibrowse:send_req(Uri, [], get, [], []) of
+        {ok, _, _, Body} ->
+            {JsonBody} = ejson:decode(Body),
+            HasCouchDBWelcome = proplists:is_defined(<<"couchdb">>, JsonBody),
+            etap:is(HasCouchDBWelcome, true, "should allow redirect to /");
+        _Else -> etap:is(false, true, <<"ibrowse fail">>)
+    end.



Mime
View raw message