mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 17:09:59 +03:00
Set _json_parse
encoding to response.charset
* Otherwise it will raise a `UnicodeDecodeError` * Tried to push a fix to django 1.11 but it doesn't receive bugfixes anymore
This commit is contained in:
parent
b1c4d8b59b
commit
6a755441ed
|
@ -11,6 +11,7 @@ from django.conf import settings
|
|||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.handlers.wsgi import WSGIHandler
|
||||
from django.test import override_settings, testcases
|
||||
from django.test.client import JSON_CONTENT_TYPE_RE
|
||||
from django.test.client import Client as DjangoClient
|
||||
from django.test.client import ClientHandler
|
||||
from django.test.client import RequestFactory as DjangoRequestFactory
|
||||
|
@ -20,6 +21,7 @@ from django.utils.http import urlencode
|
|||
|
||||
from rest_framework.compat import coreapi, requests
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.utils import json
|
||||
|
||||
|
||||
def force_authenticate(request, user=None, token=None):
|
||||
|
@ -267,6 +269,16 @@ class APIClient(APIRequestFactory, DjangoClient):
|
|||
self.handler = ForceAuthClientHandler(enforce_csrf_checks)
|
||||
self._credentials = {}
|
||||
|
||||
def _parse_json(self, response, **extra):
|
||||
if not hasattr(response, '_json'):
|
||||
if not JSON_CONTENT_TYPE_RE.match(response.get('Content-Type')):
|
||||
raise ValueError(
|
||||
'Content-Type header is "{0}", not "application/json"'
|
||||
.format(response.get('Content-Type'))
|
||||
)
|
||||
response._json = json.loads(response.content.decode(response.charset), **extra)
|
||||
return response._json
|
||||
|
||||
def credentials(self, **kwargs):
|
||||
"""
|
||||
Sets headers that will be used on every outgoing request.
|
||||
|
|
Loading…
Reference in New Issue
Block a user