Use request.content_lenght to check for a request.body existence before accessing it

This commit is contained in:
Christophe de Vienne 2012-07-11 17:10:20 +02:00
parent 92f1e76014
commit 3aa41ec7b1

View File

@ -130,9 +130,11 @@ class WSRoot(object):
def _select_protocol(self, request): def _select_protocol(self, request):
log.debug("Selecting a protocol for the following request :\n" log.debug("Selecting a protocol for the following request :\n"
"headers: %s\nbody: %s", request.headers, "headers: %s\nbody: %s", request.headers,
request.body and (len(request.body) > 512 request.content_length and (
and request.body[:512] request.content_length > 512
or request.body) or '') and request.body[:512]
or request.body)
or '')
protocol = None protocol = None
if 'wsmeproto' in request.params: if 'wsmeproto' in request.params:
return self._get_protocol(request.params['wsmeproto']) return self._get_protocol(request.params['wsmeproto'])