From 2fcfa641f6572368f60a260bfd6c8bf11a5d5b20 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Tue, 2 Feb 2010 12:12:46 +0000 Subject: would have been strange to be abble ../../_changes and not ../../../_uuids in rewriting. Instead using couch_httpd_db:handle_request we now use couch_httpd:handle_request. Add one more unitest to test it. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@905599 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/rewrite.js | 13 +++++++++++++ src/couchdb/couch_httpd.erl | 2 +- src/couchdb/couch_httpd_rewrite.erl | 25 +++++++++++++++---------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/share/www/script/test/rewrite.js b/share/www/script/test/rewrite.js index 46e7e477..87c3fac6 100644 --- a/share/www/script/test/rewrite.js +++ b/share/www/script/test/rewrite.js @@ -130,6 +130,10 @@ couchTests.rewrite = function(debug) { "query": { "key": {"c": 1} } + }, + { + "from": "uuids", + "to": "../../../_uuids" } @@ -314,6 +318,15 @@ couchTests.rewrite = function(debug) { xhr = CouchDB.request("GET", "/test_suite_db/_design/test/_rewrite/simpleForm/complexView4"); T(xhr.status == 200, "with query params"); T(/Value: doc 5/.test(xhr.responseText)); + + + // test path relative to server + + var xhr = CouchDB.request("GET", "/_uuids"); + T(xhr.status == 200); + var result = JSON.parse(xhr.responseText); + T(result.uuids.length == 1); + var first = result.uuids[0]; }); } \ No newline at end of file diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 856ab2a4..6d0230f9 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -17,7 +17,7 @@ -export([header_value/2,header_value/3,qs_value/2,qs_value/3,qs/1,path/1,absolute_uri/2,body_length/1]). -export([verify_is_server_admin/1,unquote/1,quote/1,recv/2,recv_chunked/4,error_info/1]). --export([make_fun_spec_strs/1]). +-export([make_fun_spec_strs/1, make_arity_1_fun/1]). -export([parse_form/1,json_body/1,json_body_obj/1,body/1,doc_etag/1, make_etag/1, etag_respond/3]). -export([primary_header_value/2,partition/1,serve_file/3,serve_file/4, server_header/0]). -export([start_chunked_response/3,send_chunk/2,log_request/2]). diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl index 364e6c4d..eabe98df 100644 --- a/src/couchdb/couch_httpd_rewrite.erl +++ b/src/couchdb/couch_httpd_rewrite.erl @@ -159,11 +159,6 @@ handle_rewrite_req(#httpd{ % normalize final path (fix levels "." and "..") RawPath1 = ?b2l(iolist_to_binary(normalize_path(RawPath))), - - %% get path parts, needed for CouchDB dispatching - {"/" ++ NewPath2, _, _} = mochiweb_util:urlsplit_path(RawPath1), - NewPathParts1 = [?l2b(couch_httpd:unquote(Part)) - || Part <- string:tokens(NewPath2, "/")], ?LOG_DEBUG("rewrite to ~p ~n", [RawPath1]), @@ -176,11 +171,21 @@ handle_rewrite_req(#httpd{ % cleanup, It force mochiweb to reparse raw uri. MochiReq1:cleanup(), - - % send to couchdb the rewritten request - couch_httpd_db:handle_request(Req#httpd{ - path_parts=NewPathParts1, - mochi_req=MochiReq1}) + + DefaultSpec = "{couch_httpd_db, handle_request}", + DefaultFun = couch_httpd:make_arity_1_fun( + couch_config:get("httpd", "default_handler", DefaultSpec) + ), + + UrlHandlersList = lists:map( + fun({UrlKey, SpecStr}) -> + {?l2b(UrlKey), couch_httpd:make_arity_1_fun(SpecStr)} + end, couch_config:get("httpd_global_handlers")), + UrlHandlers = dict:from_list(UrlHandlersList), + + couch_httpd:handle_request(MochiReq1, DefaultFun, + UrlHandlers, Req#httpd.db_url_handlers, + Req#httpd.design_url_handlers) end. -- cgit v1.2.3