You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ns...@apache.org on 2012/11/17 20:52:49 UTC

[14/30] git commit: Document Id and Rev in response headers

Document Id and Rev in response headers


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

Branch: refs/heads/docs
Commit: 0a64f310b43b90176bb59040e7e866978c429c88
Parents: 1a9143e
Author: Benjamin Nortier <bj...@gmail.com>
Authored: Thu Sep 20 11:01:35 2012 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Fri Nov 2 14:02:48 2012 +0100

----------------------------------------------------------------------
 src/couch_mrview/src/couch_mrview_show.erl |   14 +++++++++++++-
 src/couchdb/couch_httpd.erl                |   13 ++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/0a64f310/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 3bfa035..b2c3a32 100644
--- a/src/couch_mrview/src/couch_mrview_show.erl
+++ b/src/couch_mrview/src/couch_mrview_show.erl
@@ -144,9 +144,21 @@ send_doc_update_response(Req, Db, DDoc, UpdateName, Doc, DocId) ->
             couch_doc:validate_docid(NewDoc#doc.id),
             {ok, NewRev} = couch_db:update_doc(Db, NewDoc, Options),
             NewRevStr = couch_doc:rev_to_str(NewRev),
+            DocIdHeader = case DocId of
+                              null -> 
+                                  [{<<"json">>, {Props}}] = JsonResp0,
+                                  case lists:keyfind(<<"id">>, 1, Props) of
+                                      {_, NewDocId} -> 
+                                          [{<<"X-Couch-Id">>, NewDocId}];
+                                      false ->
+                                          []
+                                  end;
+                              DocId -> 
+                                  [{<<"X-Couch-Id">>, DocId}]
+                          end,    
             {[
                 {<<"code">>, 201},
-                {<<"headers">>, {[{<<"X-Couch-Update-NewRev">>, NewRevStr}]}}
+                {<<"headers">>, {[{<<"X-Couch-Update-NewRev">>, NewRevStr}] ++ DocIdHeader}}
                 | JsonResp0]};
         [<<"up">>, _Other, {JsonResp0}] ->
             {[{<<"code">>, 200} | JsonResp0]}

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0a64f310/src/couchdb/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 45ceebc..da47dfc 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -692,8 +692,19 @@ send_json(Req, Code, Headers, Value) ->
         {"Content-Type", negotiate_content_type(Req)},
         {"Cache-Control", "must-revalidate"}
     ],
+    IdAndRevHeaders = case Value of
+                      {Props} when is_list(Props) ->
+                          case {lists:keyfind(id, 1, Props), lists:keyfind(rev, 1, Props)} of
+                          {{_, Id}, {_, Rev}} ->
+                              [{"X-Couch-Id", Id}, {"X-Couch-Rev", Rev}];
+                          _ ->
+                              []
+                          end;
+                      _ ->
+                          []
+                      end,
     Body = [start_jsonp(), ?JSON_ENCODE(Value), end_jsonp(), $\n],
-    send_response(Req, Code, DefaultHeaders ++ Headers, Body).
+    send_response(Req, Code, DefaultHeaders ++ IdAndRevHeaders ++ Headers, Body).
 
 start_json_response(Req, Code) ->
     start_json_response(Req, Code, []).