You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by be...@apache.org on 2010/06/24 10:59:24 UTC
svn commit: r957459 - in /couchdb/branches/0.11.x:
share/www/script/test/update_documents.js src/couchdb/couch_httpd_show.erl
Author: benoitc
Date: Thu Jun 24 08:59:24 2010
New Revision: 957459
URL: http://svn.apache.org/viewvc?rev=957459&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/branches/0.11.x/share/www/script/test/update_documents.js
couchdb/branches/0.11.x/src/couchdb/couch_httpd_show.erl
Modified: couchdb/branches/0.11.x/share/www/script/test/update_documents.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/update_documents.js?rev=957459&r1=957458&r2=957459&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/update_documents.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/update_documents.js Thu Jun 24 08:59:24 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/branches/0.11.x/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_httpd_show.erl?rev=957459&r1=957458&r2=957459&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_httpd_show.erl Thu Jun 24 08:59:24 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).