couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beno...@apache.org
Subject svn commit: r928361 - in /couchdb/trunk: share/www/script/test/update_documents.js src/couchdb/couch_httpd_show.erl
Date Sun, 28 Mar 2010 09:10:51 GMT
Author: benoitc
Date: Sun Mar 28 09:10:51 2010
New Revision: 928361

URL: http://svn.apache.org/viewvc?rev=928361&view=rev
Log:
allows client to retrieve the revision of document updated via _update,
by providing it in headers. Header is named "X-Couch-Update-NewRev.


Modified:
    couchdb/trunk/share/www/script/test/update_documents.js
    couchdb/trunk/src/couchdb/couch_httpd_show.erl

Modified: couchdb/trunk/share/www/script/test/update_documents.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/update_documents.js?rev=928361&r1=928360&r2=928361&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/update_documents.js (original)
+++ couchdb/trunk/share/www/script/test/update_documents.js Sun Mar 28 09:10:51 2010
@@ -135,7 +135,11 @@ couchTests.update_documents = function(d
     headers : {"X-Couch-Full-Commit":"true"}
   });
   
+  var NewRev = xhr.getResponseHeader("X-Couch-Update-NewRev");
   doc = db.open(docid);
+  T(doc['_rev'] == NewRev);
+  
+  
   T(doc.counter == 2);
 
   // parse xml

Modified: couchdb/trunk/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_show.erl?rev=928361&r1=928360&r2=928361&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_show.erl Sun Mar 28 09:10:51 2010
@@ -125,22 +125,27 @@ 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),
-    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", "false")
of
+    {Code, 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", 
+                "false") of
             "true" ->
                 [full_commit];
             _ ->
                 []
             end,
             NewDoc = couch_doc:from_json_obj({NewJsonDoc}),
-            Code = 201,
-            {ok, _NewRev} = couch_db:update_doc(Db, NewDoc, Options);
+            {ok, NewRev} = couch_db:update_doc(Db, NewDoc, Options),
+            NewRevStr = couch_doc:rev_to_str(NewRev),
+            JsonRespWithResv =  {[{<<"headers">>, 
+                {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}} | JsonResp]},
+            {201, JsonRespWithResv};
         [<<"up">>, _Other, JsonResp] ->
-            Code = 200,
-            ok
+            {200, JsonResp}
     end,
-    JsonResp2 = json_apply_field({<<"code">>, Code}, JsonResp),
+    
+    JsonResp2 = json_apply_field({<<"code">>, Code}, JsonResp1),
     % todo set location field
     couch_httpd_external:send_external_response(Req, JsonResp2).
 



Mime
View raw message