wohali closed pull request #1620: 1612 fix, js-rewritten PUTs now work
URL: https://github.com/apache/couchdb/pull/1620
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/src/chttpd/src/chttpd_rewrite.erl
b/src/chttpd/src/chttpd_rewrite.erl
index 039390eed8..24a48248b9 100644
--- a/src/chttpd/src/chttpd_rewrite.erl
+++ b/src/chttpd/src/chttpd_rewrite.erl
@@ -64,7 +64,14 @@ do_rewrite(#httpd{mochi_req=MochiReq}=Req, {Props}=Rewrite)
when is_list(Props)
Path,
MochiReq:get(version),
Headers),
- NewMochiReq:cleanup(),
+ Body = case couch_util:get_value(<<"body">>, Props) of
+ undefined -> erlang:get(mochiweb_request_body);
+ B -> B
+ end,
+ case Body of
+ undefined -> NewMochiReq:cleanup();
+ _ -> erlang:put(mochiweb_request_body, Body)
+ end,
couch_log:debug("rewrite to ~p", [Path]),
chttpd:handle_request_int(NewMochiReq);
Code ->
diff --git a/test/javascript/tests/rewrite_js.js
b/test/javascript/tests/rewrite_js.js
index 9893127afe..22de6c940b 100644
--- a/test/javascript/tests/rewrite_js.js
+++ b/test/javascript/tests/rewrite_js.js
@@ -100,9 +100,12 @@ couchTests.rewrite = function(debug) {
return {path: '_list/simpleForm/complexView2',
query: {key: JSON.stringify({"c": 1})}};
}
- if (req.path.slice(4).join('/') === 'simpleForm/complexView4') {
- return {path: '_list/simpleForm/complexView2',
- query: {key: JSON.stringify({"c": 1})}};
+ if (req.path.slice(4).join('/') === 'simpleForm/sendBody1') {
+ return {path: '_list/simpleForm/complexView2',
+ method: 'POST',
+ query: {limit: '1'},
+ headers:{'Content-type':'application/json'},
+ body: JSON.stringify( {keys: [{"c": 1}]} )};
}
if (req.path.slice(4).join('/') === '/') {
return {path: '_view/basicView'};
@@ -283,6 +286,11 @@ couchTests.rewrite = function(debug) {
T(xhr.status == 200, "with query params");
T(/Value: doc 5/.test(xhr.responseText));
+ // COUCHDB-1612 - send body rewriting get to post
+ xhr = CouchDB.request("GET",
"/"+dbName+"/_design/test/_rewrite/simpleForm/sendBody1");
+ T(xhr.status == 200, "get->post rewrite failed:\n"+xhr.responseText);
+ T(/Value: doc 5 LineNo: 1/.test(xhr.responseText), "get->post rewrite
responded wrong:\n"+xhr.responseText);
+
// COUCHDB-2031 - path normalization versus qs params
xhr = CouchDB.request("GET",
"/"+dbName+"/_design/test/_rewrite/db/_design/test?meta=true");
T(xhr.status == 200, "path normalization works with qs params");
@@ -340,4 +348,4 @@ couchTests.rewrite = function(debug) {
// cleanup
db.deleteDb();
}
-}
+}
\ No newline at end of file
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services