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 2013/12/19 13:42:03 UTC

git commit: updated refs/heads/154-feature-gzip-post to 10a1768

Updated Branches:
  refs/heads/154-feature-gzip-post 3186e1604 -> 10a176829 (forced update)


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.

COUCHDB-154


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

Branch: refs/heads/154-feature-gzip-post
Commit: 10a17682985af09d75006d97f8a61020e6218035
Parents: cb90950
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Oct 9 11:37:18 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Dec 19 12:41:17 2013 +0000

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


http://git-wip-us.apache.org/repos/asf/couchdb/blob/10a17682/src/couchdb/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 28932ba..616c866 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -559,7 +559,8 @@ body(#httpd{req_body=ReqBody}) ->
     ReqBody.
 
 json_body(Httpd) ->
-    ?JSON_DECODE(body(Httpd)).
+    Body = body(Httpd),
+    ?JSON_DECODE(maybe_decompress(Httpd, Body)).
 
 json_body_obj(Httpd) ->
     case json_body(Httpd) of
@@ -569,6 +570,19 @@ json_body_obj(Httpd) ->
     end.
 
 
+maybe_decompress(Httpd, Body) ->
+    case header_value(Httpd, "Content-Encoding", "identity") of
+        "gzip" ->
+            try
+                zlib:gunzip(Body)
+            catch error:data_error ->
+                throw({bad_request, "Request body is not properly gzipped."})
+            end;
+        "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})) ++ "\"".