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
63511c03
Commit
63511c03
authored
Apr 23, 2015
by
Nicolas Delaby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check AcceptHeaderVersioning with content negotiation in place
parent
1fb8b248
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
rest_framework/negotiation.py
+9
-3
tests/test_versioning.py
+4
-0
No files found.
rest_framework/negotiation.py
View file @
63511c03
...
@@ -4,7 +4,7 @@ incoming request. Typically this will be based on the request's Accept header.
...
@@ -4,7 +4,7 @@ incoming request. Typically this will be based on the request's Accept header.
"""
"""
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.http
import
Http404
from
django.http
import
Http404
from
rest_framework
import
exceptions
from
rest_framework
import
HTTP_HEADER_ENCODING
,
exceptions
from
rest_framework.settings
import
api_settings
from
rest_framework.settings
import
api_settings
from
rest_framework.utils.mediatypes
import
order_by_precedence
,
media_type_matches
from
rest_framework.utils.mediatypes
import
order_by_precedence
,
media_type_matches
from
rest_framework.utils.mediatypes
import
_MediaType
from
rest_framework.utils.mediatypes
import
_MediaType
...
@@ -54,13 +54,19 @@ class DefaultContentNegotiation(BaseContentNegotiation):
...
@@ -54,13 +54,19 @@ class DefaultContentNegotiation(BaseContentNegotiation):
for
media_type
in
media_type_set
:
for
media_type
in
media_type_set
:
if
media_type_matches
(
renderer
.
media_type
,
media_type
):
if
media_type_matches
(
renderer
.
media_type
,
media_type
):
# Return the most specific media type as accepted.
# Return the most specific media type as accepted.
media_type_wrapper
=
_MediaType
(
media_type
)
if
(
if
(
_MediaType
(
renderer
.
media_type
)
.
precedence
>
_MediaType
(
renderer
.
media_type
)
.
precedence
>
_MediaType
(
media_type
)
.
precedence
media_type_wrapper
.
precedence
):
):
# Eg client requests '*/*'
# Eg client requests '*/*'
# Accepted media type is 'application/json'
# Accepted media type is 'application/json'
return
renderer
,
renderer
.
media_type
full_media_type
=
';'
.
join
(
(
renderer
.
media_type
,)
+
tuple
(
'{0}={1}'
.
format
(
key
,
value
.
decode
(
HTTP_HEADER_ENCODING
))
for
key
,
value
in
media_type_wrapper
.
params
.
items
()))
return
renderer
,
full_media_type
else
:
else
:
# Eg client requests 'application/json; indent=8'
# Eg client requests 'application/json; indent=8'
# Accepted media type is 'application/json; indent=8'
# Accepted media type is 'application/json; indent=8'
...
...
tests/test_versioning.py
View file @
63511c03
...
@@ -82,6 +82,10 @@ class TestRequestVersion:
...
@@ -82,6 +82,10 @@ class TestRequestVersion:
response
=
view
(
request
)
response
=
view
(
request
)
assert
response
.
data
==
{
'version'
:
'1.2.3'
}
assert
response
.
data
==
{
'version'
:
'1.2.3'
}
request
=
factory
.
get
(
'/endpoint/'
,
HTTP_ACCEPT
=
'*/*; version=1.2.3'
)
response
=
view
(
request
)
assert
response
.
data
==
{
'version'
:
'1.2.3'
}
request
=
factory
.
get
(
'/endpoint/'
,
HTTP_ACCEPT
=
'application/json'
)
request
=
factory
.
get
(
'/endpoint/'
,
HTTP_ACCEPT
=
'application/json'
)
response
=
view
(
request
)
response
=
view
(
request
)
assert
response
.
data
==
{
'version'
:
None
}
assert
response
.
data
==
{
'version'
:
None
}
...
...
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