Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
17532310
Commit
17532310
authored
Jul 03, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #223 from greylurk/ie-headers
Implements Accept headers from IE in the case describe in Issue 215
parents
11147ce1
73be041c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletions
+12
-1
djangorestframework/mixins.py
+2
-1
djangorestframework/tests/accept.py
+10
-0
No files found.
djangorestframework/mixins.py
View file @
17532310
...
...
@@ -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
:
...
...
djangorestframework/tests/accept.py
View file @
17532310
...
...
@@ -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."""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment