summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>2012-03-23 20:52:17 +0100
committerPaul Joseph Davis <davisp@apache.org>2012-04-25 16:54:08 -0500
commit40a4e3343179936cc35d586f78ca99f4c0b65a42 (patch)
treeb5e8165a25cad675b05b7b60ca1603a80ea5c42e
parent6c976bd948565305c006746f449dc8cd21a749e1 (diff)
downloadcouchdb-40a4e3343179936cc35d586f78ca99f4c0b65a42.tar.gz
Do not overwrite X-CouchDB-Requested-Path
Repeated rewrites would replace the initial value of X-CouchDB-Requested-Path. Fixes: COUCHDB-1442
-rw-r--r--CHANGES5
-rw-r--r--NEWS1
-rw-r--r--share/www/script/test/rewrite.js20
-rw-r--r--src/couchdb/couch_httpd_rewrite.erl7
4 files changed, 30 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index c3a05e4eb..aa9af12aa 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,11 @@ Source Repository:
* The source repository was migrated from SVN to Git.
+HTTP Interface:
+
+ * No longer rewrites the X-CouchDB-Requested-Path during recursive
+ calls to the rewriter.
+
Storage System:
* Fixed unnecessary conflict when deleting and creating a
diff --git a/NEWS b/NEWS
index 8844d92dd..bcd9c4011 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ This version has not been released yet.
* Fixed unnecessary conflict when deleting and creating a
document in the same batch.
* New and updated passwords are hashed using PBKDF2.
+ * Fix various bugs in the URL rewriter when recursion is involved.
Version 1.2.1
-------------
diff --git a/share/www/script/test/rewrite.js b/share/www/script/test/rewrite.js
index 845429221..aaf8b69e9 100644
--- a/share/www/script/test/rewrite.js
+++ b/share/www/script/test/rewrite.js
@@ -437,4 +437,24 @@ couchTests.rewrite = function(debug) {
var res = CouchDB.request("GET", "/test_suite_db/_design/invalid/_rewrite/foo");
TEquals(400, res.status, "should return 400");
+ var ddoc_requested_path = {
+ _id: "_design/requested_path",
+ rewrites:[
+ {"from": "show", "to": "_show/origin/0"},
+ {"from": "show_rewritten", "to": "_rewrite/show"}
+ ],
+ shows: {
+ origin: stringFun(function(doc, req) {
+ return req.headers["x-couchdb-requested-path"];
+ })}
+ };
+
+ db.save(ddoc_requested_path);
+ var url = "/test_suite_db/_design/requested_path/_rewrite/show";
+ var res = CouchDB.request("GET", url);
+ TEquals(url, res.responseText, "should return the original url");
+
+ var url = "/test_suite_db/_design/requested_path/_rewrite/show_rewritten";
+ var res = CouchDB.request("GET", url);
+ TEquals(url, res.responseText, "returned the original url");
}
diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl
index c8cab85d7..cb164cd1f 100644
--- a/src/couchdb/couch_httpd_rewrite.erl
+++ b/src/couchdb/couch_httpd_rewrite.erl
@@ -165,9 +165,10 @@ handle_rewrite_req(#httpd{
% normalize final path (fix levels "." and "..")
RawPath1 = ?b2l(iolist_to_binary(normalize_path(RawPath))),
- % in order to do OAuth correctly,
- % we have to save the requested path
- Headers = mochiweb_headers:enter("x-couchdb-requested-path",
+ % In order to do OAuth correctly, we have to save the
+ % requested path. We use default so chained rewriting
+ % wont replace the original header.
+ Headers = mochiweb_headers:default("x-couchdb-requested-path",
MochiReq:get(raw_path),
MochiReq:get(headers)),