diff options
-rw-r--r-- | src/couchdb/couch_httpd.erl | 2 | ||||
-rwxr-xr-x | test/etap/160-vhosts.t | 31 |
2 files changed, 29 insertions, 4 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index ae7d6c02..b25242fd 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -137,7 +137,7 @@ stop() -> redirect_to_vhost(MochiReq, DefaultFun, UrlHandlers, DbUrlHandlers, DesignUrlHandlers, VhostTarget) -> - Path = MochiReq:get(path), + Path = MochiReq:get(raw_path), Target = VhostTarget ++ Path, ?LOG_DEBUG("Vhost Target: '~p'~n", [Target]), % build a new mochiweb request diff --git a/test/etap/160-vhosts.t b/test/etap/160-vhosts.t index fa61cabf..64c51554 100755 --- a/test/etap/160-vhosts.t +++ b/test/etap/160-vhosts.t @@ -35,8 +35,15 @@ conn = nil }). +-record(user_ctx, { + name = null, + roles = [], + handler +}). + server() -> "http://127.0.0.1:5984/". dbname() -> "etap-test-db". +admin_user_ctx() -> {user_ctx, #user_ctx{roles=[<<"_admin">>]}}. config_files() -> lists:map(fun test_util:build_file/1, [ @@ -47,7 +54,7 @@ config_files() -> main(_) -> test_util:init_code_path(), - etap:plan(2), + etap:plan(3), case (catch test()) of ok -> etap:end_tests(); @@ -62,14 +69,22 @@ test() -> ibrowse:start(), crypto:start(), - couch_server:delete(list_to_binary(dbname()), []), - {ok, Db} = couch_db:create(list_to_binary(dbname()), []), + couch_server:delete(list_to_binary(dbname()), [admin_user_ctx()]), + {ok, Db} = couch_db:create(list_to_binary(dbname()), [admin_user_ctx()]), + + Doc = couch_doc:from_json_obj({[ + {<<"_id">>, <<"doc1">>}, + {<<"value">>, 666} + ]}), + {ok, _} = couch_db:update_docs(Db, [Doc]), + couch_db:ensure_full_commit(Db), %% end boilerplate, start test couch_config:set("vhosts", "example.com", "/etap-test-db", false), test_regular_request(), test_vhost_request(), + test_vhost_request_with_qs(), %% restart boilerplate couch_db:close(Db), @@ -94,3 +109,13 @@ test_vhost_request() -> etap:is(true, true, "should return database info"); _Else -> false end. + +test_vhost_request_with_qs() -> + Url = server() ++ "doc1?revs_info=true", + case ibrowse:send_req(Url, [], get, [], [{host_header, "example.com"}]) of + {ok, _, _, Body} -> + {JsonProps} = couch_util:json_decode(Body), + HasRevsInfo = proplists:is_defined(<<"_revs_info">>, JsonProps), + etap:is(HasRevsInfo, true, "should return _revs_info"); + _Else -> false + end. |