couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject [26/50] git commit: fix COUCHDB-648 - _update handler ignores "code"
Date Wed, 26 Oct 2011 18:05:33 GMT
fix COUCHDB-648 - _update handler ignores "code"

Test by Christian Carter

git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1177890 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/1319-large-headers-are-corrupted
Commit: 74613f5c413a3d10bec024bcac8fe9e7be10ac74
Parents: 9467ebb
Author: Randall Leeds <randall@apache.org>
Authored: Sat Oct 1 03:19:05 2011 +0000
Committer: Randall Leeds <randall@apache.org>
Committed: Sat Oct 1 03:19:05 2011 +0000

----------------------------------------------------------------------
 THANKS                                     |    1 +
 share/www/script/test/update_documents.js  |   24 +++++++++++++++++++++++
 src/couch_mrview/src/couch_mrview_show.erl |   16 +++++++-------
 3 files changed, 33 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/74613f5c/THANKS
----------------------------------------------------------------------
diff --git a/THANKS b/THANKS
index 95f13a7..5b1a03c 100644
--- a/THANKS
+++ b/THANKS
@@ -88,5 +88,6 @@ suggesting improvements or submitting changes. Some of these people are:
  * Trond Norbye <trond.norbye@gmail.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.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/74613f5c/share/www/script/test/update_documents.js
----------------------------------------------------------------------
diff --git a/share/www/script/test/update_documents.js b/share/www/script/test/update_documents.js
index 4d2b29f..59af459 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);
 };

http://git-wip-us.apache.org/repos/asf/couchdb/blob/74613f5c/src/couch_mrview/src/couch_mrview_show.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/src/couch_mrview_show.erl b/src/couch_mrview/src/couch_mrview_show.erl
index b23c4ac..c77abac 100644
--- a/src/couch_mrview/src/couch_mrview_show.erl
+++ b/src/couch_mrview/src/couch_mrview_show.erl
@@ -131,7 +131,7 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
     JsonDoc = couch_query_servers:json_doc(Doc),
     Cmd = [<<"updates">>, UpdateName],
     UpdateResp = couch_query_servers:ddoc_prompt(DDoc, Cmd, [JsonDoc, JsonReq]),
-    {Code, JsonResp} = case UpdateResp of
+    JsonResp = case UpdateResp of
         [<<"up">>, {NewJsonDoc}, {JsonResp0}] ->
             case couch_httpd:header_value(
                     Req, "X-Couch-Full-Commit", "false") of
@@ -143,15 +143,15 @@ 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),
-            JsonHeaders = {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]},
-            JsonRespWithRev = {[{<<"headers">>, JsonHeaders} | JsonResp0]},
-            {201, JsonRespWithRev};
-        [<<"up">>, _Other, JsonResp0] ->
-            {200, JsonResp0}
+            {[
+                {<<"code">>, 201},
+                {<<"headers">>, {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}}
+                | JsonResp0]};
+        [<<"up">>, _Other, {JsonResp0}] ->
+            {[{<<"code">>, 200} | JsonResp0]}
     end,
-    JsonResp2 = json_apply_field({<<"code">>, Code}, JsonResp),
     % todo set location field
-    couch_httpd_external:send_external_response(Req, JsonResp2).
+    couch_httpd_external:send_external_response(Req, JsonResp).
 
 
 handle_view_list_req(#httpd{method='GET'}=Req, Db, DDoc) ->


Mime
View raw message