couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject [12/50] [abbrv] couchdb commit: updated refs/heads/2041-update-ibrowse to 948e7d9
Date Fri, 07 Mar 2014 00:17:55 GMT
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/2041-update-ibrowse
Commit: 4d893387291ef4db1058a2f101bc0fd3c5064b17
Parents: f7801e6
Author: Robert Newson <rnewson@apache.org>
Authored: Fri Feb 7 20:33:57 2014 +0000
Committer: Robert Newson <rnewson@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})) ++ "\"".


Mime
View raw message