You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2012/12/04 21:43:49 UTC

[23/44] 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/57ce0eaf
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/57ce0eaf
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/57ce0eaf

Branch: refs/heads/1368-fix-multipart-header-parts
Commit: 57ce0eafd28c3204d705c44498a40d0000060f4d
Parents: 2628292
Author: Benjamin Nortier <bj...@gmail.com>
Authored: Thu Sep 20 11:01:35 2012 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Nov 8 23:37:33 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/57ce0eaf/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/57ce0eaf/src/couchdb/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 54381da..dae4af3 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -715,8 +715,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, []).