Permalink
Browse files

Document Id and Rev in response headers

  • Loading branch information...
1 parent 1a9143e commit 0a64f310b43b90176bb59040e7e866978c429c88 @bjnortier bjnortier committed with janl Sep 20, 2012
Showing with 25 additions and 2 deletions.
  1. +13 −1 src/couch_mrview/src/couch_mrview_show.erl
  2. +12 −1 src/couchdb/couch_httpd.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]}
@@ -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, []).

0 comments on commit 0a64f31

Please sign in to comment.