mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-28 13:03:45 +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
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import codecs
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -61,8 +62,8 @@ class JSONParser(BaseParser):
|
||||||
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
|
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = stream.read().decode(encoding)
|
decoded_stream = codecs.getreader(encoding)(stream)
|
||||||
return json.loads(data)
|
return json.load(decoded_stream)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
raise ParseError('JSON parse error - %s' % six.text_type(exc))
|
raise ParseError('JSON parse error - %s' % six.text_type(exc))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user