misc: process request input without calling to quixote process_inputs (#50615)

This commit is contained in:
Frédéric Péters 2021-01-27 19:11:36 +01:00
parent 4c33dca279
commit 79dd178c9d
1 changed files with 10 additions and 5 deletions

View File

@ -128,21 +128,26 @@ class HTTPRequest(quixote.http_request.HTTPRequest):
def process_inputs(self):
if self.parsed:
return
query = self.get_query()
if query:
self.form.update(quixote.http_request.parse_query(query, self.charset))
length = self.environ.get('CONTENT_LENGTH') or '0'
try:
length = int(length)
except ValueError:
raise RequestError('invalid content-length header')
ctype = self.environ.get("CONTENT_TYPE")
if self.django_request:
self.stdin = self.django_request
if ctype:
ctype, ctype_params = quixote.http_request.parse_header(ctype)
if length and ctype not in ('application/x-www-form-urlencoded', 'multipart/form-data'):
self.stdin = self.django_request
quixote.http_request.HTTPRequest.process_inputs(self)
if ctype == 'application/json' and self.stdin:
if ctype == 'application/x-www-form-urlencoded':
self._process_urlencoded(length, ctype_params)
elif ctype == 'multipart/form-data':
self._process_multipart(length, ctype_params)
elif ctype == 'application/json' and self.stdin:
from .misc import json_loads
length = int(self.environ.get('CONTENT_LENGTH') or '0')
self.stdin.seek(0) # quixote will have consumed the body
payload = self.stdin.read(length)
try:
self._json = json_loads(payload)