[Kimchi-devel] [PATCH 1/2] Return empty dict when request body is empty

Crístian Viana vianac at linux.vnet.ibm.com
Tue Nov 18 20:03:18 UTC 2014


If Kimchi receives a POST or PUT command with an empty body, a 400 error
is returned because the server cannot parse the [empty] body.

Add an additional check on the server so the request body is only parsed
if it has content; otherwise, an empty dict will be returned.

Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/control/utils.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/kimchi/control/utils.py b/src/kimchi/control/utils.py
index 64e0ac5..d26fe48 100644
--- a/src/kimchi/control/utils.py
+++ b/src/kimchi/control/utils.py
@@ -74,6 +74,9 @@ def parse_request():
         return {}
 
     if mime_in_header('Content-Type', 'application/json'):
+        if cherrypy.request.body.length == 0:
+            return {}
+
         rawbody = cherrypy.request.body.read()
         try:
             return json.loads(rawbody)
-- 
1.9.3




More information about the Kimchi-devel mailing list