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
c3891b6e
Commit
c3891b6e
authored
Apr 07, 2014
by
Dmitry Mukhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
set Retry-After header when throttled
parent
115fe048
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
1 deletions
+6
-1
rest_framework/exceptions.py
+1
-1
rest_framework/tests/test_throttling.py
+4
-0
rest_framework/views.py
+1
-0
No files found.
rest_framework/exceptions.py
View file @
c3891b6e
...
...
@@ -71,7 +71,7 @@ class UnsupportedMediaType(APIException):
class
Throttled
(
APIException
):
status_code
=
status
.
HTTP_429_TOO_MANY_REQUESTS
default_detail
=
'Request was throttled.'
extra_detail
=
"Expected available in
%
d second
%
s."
extra_detail
=
"
Expected available in
%
d second
%
s."
def
__init__
(
self
,
wait
=
None
,
detail
=
None
):
if
wait
is
None
:
...
...
rest_framework/tests/test_throttling.py
View file @
c3891b6e
...
...
@@ -117,8 +117,10 @@ class ThrottlingTests(TestCase):
response
=
view
.
as_view
()(
request
)
if
expect
is
not
None
:
self
.
assertEqual
(
response
[
'X-Throttle-Wait-Seconds'
],
expect
)
self
.
assertEqual
(
response
[
'Retry-After'
],
expect
)
else
:
self
.
assertFalse
(
'X-Throttle-Wait-Seconds'
in
response
)
self
.
assertFalse
(
'Retry-After'
in
response
)
def
test_seconds_fields
(
self
):
"""
...
...
@@ -165,11 +167,13 @@ class ThrottlingTests(TestCase):
response
=
MockView_NonTimeThrottling
.
as_view
()(
request
)
self
.
assertFalse
(
'X-Throttle-Wait-Seconds'
in
response
)
self
.
assertFalse
(
'Retry-After'
in
response
)
self
.
assertTrue
(
MockView_NonTimeThrottling
.
throttle_classes
[
0
]
.
called
)
response
=
MockView_NonTimeThrottling
.
as_view
()(
request
)
self
.
assertFalse
(
'X-Throttle-Wait-Seconds'
in
response
)
self
.
assertFalse
(
'Retry-After'
in
response
)
class
ScopedRateThrottleTests
(
TestCase
):
...
...
rest_framework/views.py
View file @
c3891b6e
...
...
@@ -61,6 +61,7 @@ def exception_handler(exc):
headers
[
'WWW-Authenticate'
]
=
exc
.
auth_header
if
getattr
(
exc
,
'wait'
,
None
):
headers
[
'X-Throttle-Wait-Seconds'
]
=
'
%
d'
%
exc
.
wait
headers
[
'Retry-After'
]
=
'
%
d'
%
exc
.
wait
return
Response
({
'detail'
:
exc
.
detail
},
status
=
exc
.
status_code
,
...
...
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