couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject couch commit: updated refs/heads/handle-missing-body to cfd0b4f
Date Sun, 12 Jul 2015 13:22:30 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/handle-missing-body [created] cfd0b4f42


Send 400 Bad Request if request body is missing


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

Branch: refs/heads/handle-missing-body
Commit: cfd0b4f4288fb63a7a57163d7785a734ad66a81b
Parents: bcb7c1a
Author: Robert Newson <rnewson@apache.org>
Authored: Sun Jul 12 14:20:25 2015 +0100
Committer: Robert Newson <rnewson@apache.org>
Committed: Sun Jul 12 14:20:25 2015 +0100

----------------------------------------------------------------------
 src/couch_httpd.erl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/cfd0b4f4/src/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd.erl b/src/couch_httpd.erl
index 8e5555c..d6d2e95 100644
--- a/src/couch_httpd.erl
+++ b/src/couch_httpd.erl
@@ -545,7 +545,12 @@ body(#httpd{req_body=ReqBody}) ->
     ReqBody.
 
 json_body(Httpd) ->
-    ?JSON_DECODE(maybe_decompress(Httpd, body(Httpd))).
+    case body(Httpd) of
+	undefined ->
+	    throw({bad_request, "JSON request body expected"});
+	Body ->
+	    ?JSON_DECODE(maybe_decompress(Httpd, Body))
+    end.
 
 json_body_obj(Httpd) ->
     case json_body(Httpd) of


Mime
View raw message