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/02/07 21:34:32 UTC

couchdb commit: updated refs/heads/2054-feature-gzip-requests to 4d89338

Updated Branches:
  refs/heads/2054-feature-gzip-requests [created] 4d8933872


Accept gzipped JSON request bodies

COUCHDB-2054


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

Branch: refs/heads/2054-feature-gzip-requests
Commit: 4d893387291ef4db1058a2f101bc0fd3c5064b17
Parents: f7801e6
Author: Robert Newson <rn...@apache.org>
Authored: Fri Feb 7 20:33:57 2014 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Fri Feb 7 20:33:57 2014 +0000

----------------------------------------------------------------------
 src/couchdb/couch_httpd.erl | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/4d893387/src/couchdb/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index acc20d7..f00fdd0 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -544,7 +544,7 @@ body(#httpd{req_body=ReqBody}) ->
     ReqBody.
 
 json_body(Httpd) ->
-    ?JSON_DECODE(body(Httpd)).
+    ?JSON_DECODE(maybe_decompress(Httpd, body(Httpd))).
 
 json_body_obj(Httpd) ->
     case json_body(Httpd) of
@@ -554,6 +554,15 @@ json_body_obj(Httpd) ->
     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.
 
 doc_etag(#doc{revs={Start, [DiskRev|_]}}) ->
     "\"" ++ ?b2l(couch_doc:rev_to_str({Start, DiskRev})) ++ "\"".