couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject couchdb commit: updated refs/heads/1.x.x to b6638e3
Date Thu, 17 Sep 2015 10:39:08 GMT
Repository: couchdb
Updated Branches:
  refs/heads/1.x.x 90a9dac99 -> b6638e35e


Fix duplicated Content-Type for show/update functions

COUCHDB-1876

Signed-off-by: Alexander Shorin <kxepal@apache.org>


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

Branch: refs/heads/1.x.x
Commit: b6638e35e326e7fafdfddce10ec3e6a990c4639f
Parents: 90a9dac
Author: Artur Mazurek <artur.s.mazurek@gmail.com>
Authored: Thu Sep 17 13:36:31 2015 +0300
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Thu Sep 17 13:37:59 2015 +0300

----------------------------------------------------------------------
 src/couchdb/couch_httpd.erl | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/b6638e35/src/couchdb/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 94eab7d..b73b0bd 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -752,11 +752,8 @@ start_json_response(Req, Code) ->
 
 start_json_response(Req, Code, Headers) ->
     initialize_jsonp(Req),
-    DefaultHeaders = [
-        {"Content-Type", negotiate_content_type(Req)},
-        {"Cache-Control", "must-revalidate"}
-    ],
-    {ok, Resp} = start_chunked_response(Req, Code, DefaultHeaders ++ Headers),
+    AllHeaders = maybe_add_default_headers(Req, Headers),
+    {ok, Resp} = start_chunked_response(Req, Code, AllHeaders),
     case start_jsonp() of
         [] -> ok;
         Start -> send_chunk(Resp, Start)
@@ -767,6 +764,21 @@ end_json_response(Resp) ->
     send_chunk(Resp, end_jsonp() ++ [$\n]),
     last_chunk(Resp).
 
+
+maybe_add_default_headers(ForRequest, ToHeaders) ->
+    DefaultHeaders = [
+        {"Content-Type", negotiate_content_type(ForRequest)},
+        {"Cache-Control", "must-revalidate"}
+    ],
+    lists:foldl(fun maybe_add_header/2, ToHeaders, DefaultHeaders).
+
+maybe_add_header({HeaderName, HeaderValue}, ToHeaders) ->
+    case lists:keyfind(HeaderName, 1, ToHeaders) of
+        false -> ToHeaders ++ [{HeaderName, HeaderValue}];
+        _Found -> ToHeaders
+    end.
+
+
 initialize_jsonp(Req) ->
     case get(jsonp) of
         undefined -> put(jsonp, qs_value(Req, "callback", no_jsonp));


Mime
View raw message