couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [06/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74
Date Fri, 01 Aug 2014 09:05:42 GMT
 Add X-Couch-Update-NewRev and X-Couch-Id to _update response

This is porting commits from CouchDB:

ef7ab7e4e414d53fe5c12993d29b193ed3cdfd42
 - allow client to get new _rev from _update via X-Couch-Update-NewRev
 - I left out porting the JS test
98515bf0b990ca096ec5a47b9cd048427a0ec66c
 - Return X-Couch-Id from show functions if doc is created


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

Branch: refs/heads/windsor-merge
Commit: 31b7d4a721f3f5b7145575d70724f3c6a2d47372
Parents: 1e0c52a
Author: Michael Rhodes <mike.rhodes@gmail.com>
Authored: Sat Apr 6 21:54:47 2013 -0400
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Jul 29 17:12:06 2014 +0100

----------------------------------------------------------------------
 src/chttpd_show.erl | 48 +++++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/31b7d4a7/src/chttpd_show.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_show.erl b/src/chttpd_show.erl
index 7dc5337..18f64cb 100644
--- a/src/chttpd_show.erl
+++ b/src/chttpd_show.erl
@@ -119,27 +119,37 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
     JsonDoc = couch_query_servers:json_doc(Doc),
     Cmd = [<<"updates">>, UpdateName],
     W = couch_httpd:qs_value(Req, "w", integer_to_list(mem3:quorum(Db))),
-    case couch_query_servers:ddoc_prompt(DDoc, Cmd, [JsonDoc, JsonReq]) of
-    [<<"up">>, {NewJsonDoc}, JsonResp] ->
-        case chttpd:header_value(Req, "X-Couch-Full-Commit", "false") of
-        "true" ->
-            Options = [full_commit, {user_ctx, Req#httpd.user_ctx}, {w, W}];
-        _ ->
-            Options = [{user_ctx, Req#httpd.user_ctx}, {w, W}]
-        end,
-        NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
-        case fabric:update_doc(Db, NewDoc, Options) of
-        {ok, _} ->
-            Code = 201;
-        {accepted, _} ->
-            Code = 202
-        end;
-    [<<"up">>, _Other, JsonResp] ->
-        Code = 200
+    UpdateResp = couch_query_servers:ddoc_prompt(DDoc, Cmd, [JsonDoc, JsonReq]),
+    JsonResp = case UpdateResp of
+        [<<"up">>, {NewJsonDoc}, {JsonResp0}] ->
+            case chttpd:header_value(Req, "X-Couch-Full-Commit", "false") of
+            "true" ->
+                Options = [full_commit, {user_ctx, Req#httpd.user_ctx}, {w, W}];
+            _ ->
+                Options = [{user_ctx, Req#httpd.user_ctx}, {w, W}]
+            end,
+            NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
+            couch_doc:validate_docid(NewDoc#doc.id),
+            {UpdateResult, NewRev} = fabric:update_doc(Db, NewDoc, Options),
+            NewRevStr = couch_doc:rev_to_str(NewRev),
+            case {UpdateResult, NewRev} of
+            {ok, _} ->
+                Code = 201;
+            {accepted, _} ->
+                Code = 202
+            end,
+            {[
+                {<<"code">>, Code},
+                {<<"headers">>, {[
+                    {<<"X-Couch-Update-NewRev">>, NewRevStr},
+                    {<<"X-Couch-Id">>, NewDoc#doc.id}
+                ]}}
+                | JsonResp0]};
+        [<<"up">>, _Other, {JsonResp0}] ->
+            {[{<<"code">>, 200} | JsonResp0]}
     end,
-    JsonResp2 = json_apply_field({<<"code">>, Code}, JsonResp),
     % todo set location field
-    chttpd_external:send_external_response(Req, JsonResp2).
+    chttpd_external:send_external_response(Req, JsonResp).
 
 
 % view-list request with view and list from same design doc.


Mime
View raw message