Updated Branches: refs/heads/154-feature-gzip-post [created] 899a91927
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. Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/899a9192 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/899a9192 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/899a9192 Branch: refs/heads/154-feature-gzip-post Commit: 899a919275d16dfbb016945fb818e4791af969d6 Parents: cb90950 Author: Adam Kocoloski <[email protected]> Authored: Wed Oct 9 11:37:18 2013 -0400 Committer: Robert Newson <[email protected]> Committed: Sun Dec 15 10:00:13 2013 +0100 ---------------------------------------------------------------------- src/couchdb/couch_httpd.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/899a9192/src/couchdb/couch_httpd.erl ---------------------------------------------------------------------- diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 28932ba..a370bd2 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,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})) ++ "\"".
