couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [6/8] git commit: Document Id and Rev in response headers
Date Tue, 13 Nov 2012 14:01:55 GMT
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/7a2836ee
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/7a2836ee
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/7a2836ee

Branch: refs/heads/1585-feature-per-module-log-levels
Commit: 7a2836ee5244ea11d0a5e8e7b35c00841b257d7f
Parents: ff50195
Author: Benjamin Nortier <bjnortier@gmail.com>
Authored: Thu Sep 20 11:01:35 2012 +0100
Committer: Jan Lehnardt <jan@apache.org>
Committed: Tue Nov 13 15:01:54 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/7a2836ee/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/7a2836ee/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, []).


Mime
View raw message