mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 21:24:33 +03:00
Merge pull request #5147 from imdark/patch-1
Improve memory footprint when reading large JSON requests.
This commit is contained in:
commit
823eea2d59
|
@ -6,6 +6,7 @@ on the request, such as form content or json encoded data.
|
|||
"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import codecs
|
||||
import json
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -61,8 +62,8 @@ class JSONParser(BaseParser):
|
|||
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
|
||||
|
||||
try:
|
||||
data = stream.read().decode(encoding)
|
||||
return json.loads(data)
|
||||
decoded_stream = codecs.getreader(encoding)(stream)
|
||||
return json.load(decoded_stream)
|
||||
except ValueError as exc:
|
||||
raise ParseError('JSON parse error - %s' % six.text_type(exc))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user