Read application/json data into request.json.
(entity)
| 4 | |
| 5 | |
| 6 | def json_processor(entity): |
| 7 | """Read application/json data into request.json.""" |
| 8 | if not entity.headers.get(ntou('Content-Length'), ntou('')): |
| 9 | raise cherrypy.HTTPError(411) |
| 10 | |
| 11 | body = entity.fp.read() |
| 12 | with cherrypy.HTTPError.handle(ValueError, 400, 'Invalid JSON document'): |
| 13 | cherrypy.serving.request.json = json.decode(body.decode('utf-8')) |
| 14 | |
| 15 | |
| 16 | def json_in(content_type=[ntou('application/json'), ntou('text/javascript')], |