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 2017/11/01 07:02:58 UTC
[couchdb] 02/07: Merge default update response headers with custom
ones
This is an automated email from the ASF dual-hosted git repository.
jan pushed a commit to branch 1.x.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 56c15472ff90d0ae84165daed55c5d3279e82e62
Author: Alexander Shorin <kx...@apache.org>
AuthorDate: Sat Dec 12 20:59:57 2015 +0300
Merge default update response headers with custom ones
COUCHDB-1447
---
share/doc/src/whatsnew/1.7.rst | 2 ++
src/couch_mrview/src/couch_mrview_show.erl | 30 +++++++++++++++++++++++-------
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/share/doc/src/whatsnew/1.7.rst b/share/doc/src/whatsnew/1.7.rst
index fd6287a..b14b1f6 100644
--- a/share/doc/src/whatsnew/1.7.rst
+++ b/share/doc/src/whatsnew/1.7.rst
@@ -79,6 +79,8 @@ HTTP Server
Query Server
------------
+- :issue:`1447`: Custom response headers from design functions get merged with
+ default ones.
- :commit:`7779c11`: Upgrade Coffeescript to version 1.10.
jquery.couch.js
diff --git a/src/couch_mrview/src/couch_mrview_show.erl b/src/couch_mrview/src/couch_mrview_show.erl
index f8fa837..3e0e743 100644
--- a/src/couch_mrview/src/couch_mrview_show.erl
+++ b/src/couch_mrview/src/couch_mrview_show.erl
@@ -146,13 +146,11 @@ 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),
- {[
- {<<"code">>, 201},
- {<<"headers">>, {[
- {<<"X-Couch-Update-NewRev">>, NewRevStr},
- {<<"X-Couch-Id">>, NewDoc#doc.id}
- ]}}
- | JsonResp0]};
+ {JsonResp1} = apply_headers(JsonResp0, [
+ {<<"X-Couch-Update-NewRev">>, NewRevStr},
+ {<<"X-Couch-Id">>, NewDoc#doc.id}
+ ]),
+ {[{<<"code">>, 201} | JsonResp1]};
[<<"up">>, _Other, {JsonResp0}] ->
{[{<<"code">>, 200} | JsonResp0]}
end,
@@ -350,6 +348,24 @@ apply_etag({ExternalResponse}, CurrentEtag) ->
end.
+apply_headers(JsonResp, []) ->
+ JsonResp;
+apply_headers(JsonResp, NewHeaders) ->
+ case couch_util:get_value(<<"headers">>, JsonResp) of
+ undefined ->
+ {[{<<"headers">>, {NewHeaders}}| JsonResp]};
+ JsonHeaders ->
+ Headers = apply_headers1(JsonHeaders, NewHeaders),
+ NewKV = {<<"headers">>, Headers},
+ {lists:keyreplace(<<"headers">>, 1, JsonResp, NewKV)}
+ end.
+apply_headers1(JsonHeaders, [{Key, Value} | Rest]) ->
+ NewJsonHeaders = json_apply_field({Key, Value}, JsonHeaders),
+ apply_headers1(NewJsonHeaders, Rest);
+apply_headers1(JsonHeaders, []) ->
+ JsonHeaders.
+
+
% Maybe this is in the proplists API
% todo move to couch_util
json_apply_field(H, {L}) ->
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.