This is an automated email from the ASF dual-hosted git repository.
iilyak pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/main by this push:
new 1be2312 Use `req_body` field if present
new 5cfa4a8 Merge pull request #3268 from cloudant/reuse-json-body
1be2312 is described below
commit 1be23124b7a867a966ce39ec66231bc2d2779ca9
Author: ILYA Khlopotov <[email protected]>
AuthorDate: Mon Nov 16 04:01:21 2020 -0800
Use `req_body` field if present
When we call `couch_httpd:json_body/1` we can have `req_body` already set.
In this case we should return the field as is without any attempt to
decompress or decode it. This PR brings the approach we use in `chttpd`
into `couch_httpd`.
---
src/couch/src/couch_httpd.erl | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/couch/src/couch_httpd.erl b/src/couch/src/couch_httpd.erl
index 8f7fedd..53d14d7 100644
--- a/src/couch/src/couch_httpd.erl
+++ b/src/couch/src/couch_httpd.erl
@@ -599,13 +599,16 @@ body(#httpd{mochi_req=MochiReq, req_body=undefined}) ->
body(#httpd{req_body=ReqBody}) ->
ReqBody.
-json_body(Httpd) ->
+json_body(#httpd{req_body=undefined} = Httpd) ->
case body(Httpd) of
undefined ->
throw({bad_request, "Missing request body"});
Body ->
?JSON_DECODE(maybe_decompress(Httpd, Body))
- end.
+ end;
+
+json_body(#httpd{req_body=ReqBody}) ->
+ ReqBody.
json_body_obj(Httpd) ->
case json_body(Httpd) of