diff options
Diffstat (limited to 'src/couchdb/couch_httpd.erl')
-rw-r--r-- | src/couchdb/couch_httpd.erl | 16 |
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})) ++ "\"". |