You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ju...@apache.org on 2020/09/24 10:09:24 UTC
[couchdb] branch master updated: Preserve query string rewrite when
the request contains a body
This is an automated email from the ASF dual-hosted git repository.
juanjo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/master by this push:
new 3b815a6 Preserve query string rewrite when the request contains a body
3b815a6 is described below
commit 3b815a6d1d13d37958df6914ee3a87e221911b95
Author: Juanjo Rodriguez <ju...@apache.org>
AuthorDate: Thu Sep 24 07:45:05 2020 +0200
Preserve query string rewrite when the request contains a body
---
src/chttpd/src/chttpd_rewrite.erl | 3 ++-
test/javascript/tests/rewrite_js.js | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/chttpd/src/chttpd_rewrite.erl b/src/chttpd/src/chttpd_rewrite.erl
index 0196513..1c2c1f3 100644
--- a/src/chttpd/src/chttpd_rewrite.erl
+++ b/src/chttpd/src/chttpd_rewrite.erl
@@ -71,8 +71,9 @@ do_rewrite(#httpd{mochi_req=MochiReq}=Req, {Props}=Rewrite) when is_list(Props)
undefined -> erlang:get(mochiweb_request_body);
B -> B
end,
+ NewMochiReq:cleanup(),
case Body of
- undefined -> NewMochiReq:cleanup();
+ undefined -> [];
_ -> erlang:put(mochiweb_request_body, Body)
end,
couch_log:debug("rewrite to ~p", [Path]),
diff --git a/test/javascript/tests/rewrite_js.js b/test/javascript/tests/rewrite_js.js
index 22de6c9..0ccdd65 100644
--- a/test/javascript/tests/rewrite_js.js
+++ b/test/javascript/tests/rewrite_js.js
@@ -345,6 +345,22 @@ couchTests.rewrite = function(debug) {
var xhr = CouchDB.request("GET", url);
TEquals(400, xhr.status);
+ // test requests with body preserve the query string rewrite
+ var ddoc_qs = {
+ "_id": "_design/qs",
+ "rewrites": "function (r) { return {path: '../../_changes', query: {'filter': '_doc_ids'}};};"
+ }
+ db.save(ddoc_qs);
+ db.save({"_id": "qs1", "foo": "bar"});
+ db.save({"_id": "qs2", "foo": "bar"});
+
+ var url = "/"+dbName+"/_design/qs/_rewrite";
+
+ var xhr = CouchDB.request("POST", url, {body: JSON.stringify({"doc_ids": ["qs2"]})});
+ var result = JSON.parse(xhr.responseText);
+ T(xhr.status == 200);
+ T(result.results.length == 1, "Only one doc is expected");
+ TEquals(result.results[0].id, "qs2");
// cleanup
db.deleteDb();
}