summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Leeds <randall@apache.org>2011-10-01 03:20:05 +0000
committerRandall Leeds <randall@apache.org>2011-10-01 03:20:05 +0000
commite77949221f63a011787118637cb549abfbd8e5e8 (patch)
tree26a4e35c58ab7a7fcdc42a992cf2f53a58d7fe16
parente14981fff72c58d4b552aae51c877a9c01c997ef (diff)
fix COUCHDB-648 - _update handler ignores "code"
Test by Christian Carter This is a backport of r1177890 git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1177892 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--THANKS1
-rw-r--r--share/www/script/test/update_documents.js24
-rw-r--r--src/couchdb/couch_httpd_show.erl16
3 files changed, 32 insertions, 9 deletions
diff --git a/THANKS b/THANKS
index 76a0c19b..470c3937 100644
--- a/THANKS
+++ b/THANKS
@@ -82,5 +82,6 @@ suggesting improvements or submitting changes. Some of these people are:
* Caolan McMahon <caolan.mcmahon@googlemail.com>
* Alexander Shorin <kxepal@gmail.com>
* Christopher Bonhage <queezey@me.com>
+ * Christian Carter <cdcarter@gmail.com>
For a list of authors see the `AUTHORS` file.
diff --git a/share/www/script/test/update_documents.js b/share/www/script/test/update_documents.js
index 4d2b29fc..59af4597 100644
--- a/share/www/script/test/update_documents.js
+++ b/share/www/script/test/update_documents.js
@@ -75,6 +75,17 @@ couchTests.update_documents = function(debug) {
}),
"get-uuid" : stringFun(function(doc, req) {
return [null, req.uuid];
+ }),
+ "code-n-bump" : stringFun(function(doc,req) {
+ if (!doc.counter) doc.counter = 0;
+ doc.counter += 1;
+ var message = "<h1>bumped it!</h1>";
+ resp = {"code": 302, "body": message}
+ return [doc, resp];
+ }),
+ "resp-code" : stringFun(function(doc,req) {
+ resp = {"code": 302}
+ return [null, resp];
})
}
};
@@ -179,4 +190,17 @@ couchTests.update_documents = function(debug) {
var doc = db.open("with/slash");
TEquals(2, doc.counter, "counter should be 2");
+
+ // COUCHDB-648 - the code in the JSON response should be honored
+
+ xhr = CouchDB.request("PUT", "/test_suite_db/_design/update/_update/code-n-bump/"+docid, {
+ headers : {"X-Couch-Full-Commit":"true"}
+ });
+ T(xhr.status == 302);
+ T(xhr.responseText == "<h1>bumped it!</h1>");
+ doc = db.open(docid);
+ T(doc.counter == 3);
+
+ xhr = CouchDB.request("POST", "/test_suite_db/_design/update/_update/resp-code/");
+ T(xhr.status == 302);
};
diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl
index 742b0f20..58f046e4 100644
--- a/src/couchdb/couch_httpd_show.erl
+++ b/src/couchdb/couch_httpd_show.erl
@@ -127,7 +127,7 @@ handle_doc_update_req(Req, _Db, _DDoc) ->
send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
JsonReq = couch_httpd_external:json_req_obj(Req, Db, DocId),
JsonDoc = couch_query_servers:json_doc(Doc),
- {Code, JsonResp1} = case couch_query_servers:ddoc_prompt(DDoc,
+ JsonResp1 = case couch_query_servers:ddoc_prompt(DDoc,
[<<"updates">>, UpdateName], [JsonDoc, JsonReq]) of
[<<"up">>, {NewJsonDoc}, {JsonResp}] ->
Options = case couch_httpd:header_value(Req, "X-Couch-Full-Commit",
@@ -140,16 +140,14 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
{ok, NewRev} = couch_db:update_doc(Db, NewDoc, Options),
NewRevStr = couch_doc:rev_to_str(NewRev),
- JsonRespWithRev = {[{<<"headers">>,
- {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}} | JsonResp]},
- {201, JsonRespWithRev};
- [<<"up">>, _Other, JsonResp] ->
- {200, JsonResp}
+ {[{<<"code">>, 201}, {<<"headers">>,
+ {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}} | JsonResp]};
+ [<<"up">>, _Other, {JsonResp}] ->
+ {[{<<"code">>, 200} | JsonResp]}
end,
-
- JsonResp2 = couch_util:json_apply_field({<<"code">>, Code}, JsonResp1),
+
% todo set location field
- couch_httpd_external:send_external_response(Req, JsonResp2).
+ couch_httpd_external:send_external_response(Req, JsonResp1).
% view-list request with view and list from same design doc.