aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework
diff options
context:
space:
mode:
authorXavier Ordoquy2013-01-07 23:26:14 +0100
committerXavier Ordoquy2013-01-07 23:26:14 +0100
commit510d6a3c5540bbc20406ff79ce5f95d97b2a63f3 (patch)
tree2a19077854f71266793c59222cc987e4d0848ef0 /rest_framework
parent22a7dc27d8638b001d513598e5f0ba13698a1186 (diff)
downloaddjango-rest-framework-510d6a3c5540bbc20406ff79ce5f95d97b2a63f3.tar.bz2
Introduced HTTP_HEADER_ENCODING.
Diffstat (limited to 'rest_framework')
-rw-r--r--rest_framework/authentication.py5
-rw-r--r--rest_framework/settings.py3
2 files changed, 7 insertions, 1 deletions
diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py
index 42f6f02b..c50bf944 100644
--- a/rest_framework/authentication.py
+++ b/rest_framework/authentication.py
@@ -8,6 +8,7 @@ from rest_framework import exceptions
from rest_framework.compat import CsrfViewMiddleware
from rest_framework.compat import smart_text
from rest_framework.authtoken.models import Token
+from rest_framework.settings import api_settings
import base64
@@ -37,7 +38,9 @@ class BasicAuthentication(BaseAuthentication):
auth = request.META['HTTP_AUTHORIZATION'].split()
if len(auth) == 2 and auth[0].lower() == "basic":
try:
- auth_parts = base64.b64decode(auth[1].encode('iso-8859-1')).decode('iso-8859-1').partition(':')
+ encoding = api_settings.HTTP_HEADER_ENCODING
+ b = base64.b64decode(auth[1].encode(encoding))
+ auth_parts = b.decode(encoding).partition(':')
except TypeError:
return None
diff --git a/rest_framework/settings.py b/rest_framework/settings.py
index 186833b5..2358d188 100644
--- a/rest_framework/settings.py
+++ b/rest_framework/settings.py
@@ -75,6 +75,9 @@ DEFAULTS = {
'URL_FORMAT_OVERRIDE': 'format',
'FORMAT_SUFFIX_KWARG': 'format',
+
+ # Header encoding (see RFC5987)
+ 'HTTP_HEADER_ENCODING': 'iso-8859-1',
}