You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by be...@apache.org on 2010/02/02 13:12:49 UTC
svn commit: r905599 - in /couchdb/trunk: share/www/script/test/rewrite.js
src/couchdb/couch_httpd.erl src/couchdb/couch_httpd_rewrite.erl
Author: benoitc
Date: Tue Feb 2 12:12:46 2010
New Revision: 905599
URL: http://svn.apache.org/viewvc?rev=905599&view=rev
Log:
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.
Modified:
couchdb/trunk/share/www/script/test/rewrite.js
couchdb/trunk/src/couchdb/couch_httpd.erl
couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl
Modified: couchdb/trunk/share/www/script/test/rewrite.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/rewrite.js?rev=905599&r1=905598&r2=905599&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/rewrite.js (original)
+++ couchdb/trunk/share/www/script/test/rewrite.js Tue Feb 2 12:12:46 2010
@@ -130,6 +130,10 @@
"query": {
"key": {"c": 1}
}
+ },
+ {
+ "from": "uuids",
+ "to": "../../../_uuids"
}
@@ -314,6 +318,15 @@
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
Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=905599&r1=905598&r2=905599&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Tue Feb 2 12:12:46 2010
@@ -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]).
Modified: couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl?rev=905599&r1=905598&r2=905599&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_rewrite.erl Tue Feb 2 12:12:46 2010
@@ -159,11 +159,6 @@
% 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 @@
% 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.