diff options
| author | Tom Christie | 2012-07-03 03:42:06 -0700 |
|---|---|---|
| committer | Tom Christie | 2012-07-03 03:42:06 -0700 |
| commit | 17532310a27e71673e5ffb32fffcbccb2dabc536 (patch) | |
| tree | 8f5e466589b54c349a1b582597bd83eb17fa9383 | |
| parent | 11147ce13e754f47b9cdc8d0de8a071aa540882f (diff) | |
| parent | 73be041c474900423c5258b57b3d71d566aea6df (diff) | |
| download | django-rest-framework-17532310a27e71673e5ffb32fffcbccb2dabc536.tar.bz2 | |
Merge pull request #223 from greylurk/ie-headers
Implements Accept headers from IE in the case describe in Issue 215
| -rw-r--r-- | djangorestframework/mixins.py | 3 | ||||
| -rw-r--r-- | djangorestframework/tests/accept.py | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py index 6c8f8179..0f292b4e 100644 --- a/djangorestframework/mixins.py +++ b/djangorestframework/mixins.py @@ -274,7 +274,8 @@ class ResponseMixin(object): accept_list = [request.GET.get(self._ACCEPT_QUERY_PARAM)] elif (self._IGNORE_IE_ACCEPT_HEADER and 'HTTP_USER_AGENT' in request.META and - MSIE_USER_AGENT_REGEX.match(request.META['HTTP_USER_AGENT'])): + MSIE_USER_AGENT_REGEX.match(request.META['HTTP_USER_AGENT']) and + request.META.get('HTTP_X_REQUESTED_WITH', '') != 'XMLHttpRequest'): # Ignore MSIE's broken accept behavior and do something sensible instead accept_list = ['text/html', '*/*'] elif 'HTTP_ACCEPT' in request.META: diff --git a/djangorestframework/tests/accept.py b/djangorestframework/tests/accept.py index 21aba589..7f4eb320 100644 --- a/djangorestframework/tests/accept.py +++ b/djangorestframework/tests/accept.py @@ -50,6 +50,16 @@ class UserAgentMungingTest(TestCase): resp = self.view(req) self.assertEqual(resp['Content-Type'], 'text/html') + def test_dont_munge_msie_with_x_requested_with_header(self): + """Send MSIE user agent strings, and an X-Requested-With header, and + ensure that we get a JSON response if we set a */* Accept header.""" + for user_agent in (MSIE_9_USER_AGENT, + MSIE_8_USER_AGENT, + MSIE_7_USER_AGENT): + req = self.req.get('/', HTTP_ACCEPT='*/*', HTTP_USER_AGENT=user_agent, HTTP_X_REQUESTED_WITH='XMLHttpRequest') + resp = self.view(req) + self.assertEqual(resp['Content-Type'], 'application/json') + def test_dont_rewrite_msie_accept_header(self): """Turn off _IGNORE_IE_ACCEPT_HEADER, send MSIE user agent strings and ensure that we get a JSON response if we set a */* accept header.""" |
