You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/28 13:59:43 UTC
[20/50] chttpd commit: updated refs/heads/master to 58020ab
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/master
Commit: 6ffa347d94248325d7828bee7dfc1ff54ec262e2
Parents: b500211
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Oct 9 11:37:18 2013 -0400
Committer: Robert Newson <rn...@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.