couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [23/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74
Date Fri, 01 Aug 2014 09:05:59 GMT
Allows clients to send gzipped JSON bodies

A request with a Content-Encoding other than "gzip" or "identity" will
receive a 415 Unsupported Media Type response.

BugzID: 24000


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

Branch: refs/heads/windsor-merge
Commit: 6ffa347d94248325d7828bee7dfc1ff54ec262e2
Parents: b500211
Author: Adam Kocoloski <adam@cloudant.com>
Authored: Wed Oct 9 11:37:18 2013 -0400
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Jul 29 18:20:15 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/6ffa347d/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 08be216..82aab96 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -508,7 +508,7 @@ json_body(Httpd) ->
         undefined ->
             throw({bad_request, "Missing request body"});
         Body ->
-            ?JSON_DECODE(Body)
+            ?JSON_DECODE(maybe_decompress(Httpd, Body))
     end.
 
 json_body_obj(Httpd) ->
@@ -868,3 +868,13 @@ json_stack_item(_) ->
 
 json_stack_arity(A) ->
     if is_integer(A) -> A; is_list(A) -> length(A); true -> 0 end.
+
+maybe_decompress(Httpd, Body) ->
+    case header_value(Httpd, "Content-Encoding", "identity") of
+    "gzip" ->
+        zlib:gunzip(Body);
+    "identity" ->
+        Body;
+    Else ->
+        throw({bad_ctype, [Else, " is not a supported content encoding."]})
+    end.


Mime
View raw message