diff options
author | Benoit Chesneau <benoitc@apache.org> | 2010-03-28 09:10:51 +0000 |
---|---|---|
committer | Benoit Chesneau <benoitc@apache.org> | 2010-03-28 09:10:51 +0000 |
commit | ef7ab7e4e414d53fe5c12993d29b193ed3cdfd42 (patch) | |
tree | eac9b8e983cddb4d5ffef784de368e6d001b2e03 /src/couchdb | |
parent | ed7e7c686fae7f1d2e3f149c2f2ed8854c4f95c8 (diff) |
allows client to retrieve the revision of document updated via _update,
by providing it in headers. Header is named "X-Couch-Update-NewRev.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@928361 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r-- | src/couchdb/couch_httpd_show.erl | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl index 72c6bae1..c0bb21e7 100644 --- a/src/couchdb/couch_httpd_show.erl +++ b/src/couchdb/couch_httpd_show.erl @@ -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). |