You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2012/05/01 15:28:36 UTC

[2/2] git commit: Backport (master): Do not overwrite X-CouchDB-Requested-Path

Backport (master): Do not overwrite X-CouchDB-Requested-Path

Master commit id: 40a4e33.

Repeated rewrites would replace the initial value of
X-CouchDB-Requested-Path.

Fixes: COUCHDB-1442


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/56744f2f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/56744f2f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/56744f2f

Branch: refs/heads/COUCHDB-1441-1442-1.2.x
Commit: 56744f2f4b63c396a68e892fcfaec1a84ab95bf2
Parents: 58a9b6f
Author: Ronny Pfannschmidt <Ro...@gmx.de>
Authored: Fri Mar 23 20:52:17 2012 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Tue May 1 14:02:25 2012 +0100

----------------------------------------------------------------------
 CHANGES                             |    5 +++++
 NEWS                                |    2 ++
 share/www/script/test/rewrite.js    |   20 ++++++++++++++++++++
 src/couchdb/couch_httpd_rewrite.erl |    7 ++++---
 4 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/56744f2f/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 265ff6b..8524110 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,11 @@ Version 1.2.1
 
 This version has not been released yet.
 
+HTTP Interface:
+
+ * No longer rewrites the X-CouchDB-Requested-Path during recursive
+   calls to the rewriter.
+
 Version 1.2.0
 -------------
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/56744f2f/NEWS
----------------------------------------------------------------------
diff --git a/NEWS b/NEWS
index caf2089..93346f6 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ Version 1.2.1
 
 This version has not been released yet.
 
+ * Fix various bugs in the URL rewriter when recursion is involved.
+
 Version 1.2.0
 -------------
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/56744f2f/share/www/script/test/rewrite.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/rewrite.js b/share/www/script/test/rewrite.js
index 8454292..aaf8b69 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");
 }

http://git-wip-us.apache.org/repos/asf/couchdb/blob/56744f2f/src/couchdb/couch_httpd_rewrite.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd_rewrite.erl b/src/couchdb/couch_httpd_rewrite.erl
index c8cab85..cb164cd 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)),