summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2013-10-09 11:37:18 -0400
committerRobert Newson <rnewson@apache.org>2013-12-19 12:41:17 +0000
commit10a17682985af09d75006d97f8a61020e6218035 (patch)
treecd960b41f9d8502a2817f3bc32a077ee2a309de6
parentcb9095053b3f5bddaae9dae9721d4d29a01734f9 (diff)
downloadcouchdb-154-feature-gzip-post.tar.gz
Allows clients to send gzipped JSON bodies154-feature-gzip-post
A request with a Content-Encoding other than "gzip" or "identity" will receive a 415 Unsupported Media Type response. COUCHDB-154
-rw-r--r--src/couchdb/couch_httpd.erl16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 28932ba0f..616c8662b 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})) ++ "\"".