hapic
hapic copied to clipboard
Do not check body for pyramid context to avoid loading all request
line 53 of ext/pyramid/context.py does :
if req.body and req.content_type in ("application/json", "application/json-rpc"): json_body = req.json_body # TODO : raise exception if not correct , return 400 if uncorrect instead ? else: json_body = {}
req.body come from pyramid request and is processed by webob.
Problem is, that, checking req.body mean loading data and potentially all request (if you send a 700m file, it will load them in memory).
Simple fix may be
if req.content_type in ("application/json", "application/json-rpc") and req.body :
we can also do no try to load body and do a try catch on "req.json_body"
We should later probably return exception in case of empty content but changing the behavior here, mean breaking code (it happened in tracim with case we received are application/json content type with fully empty body, not json parsable)