mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
set Retry-After header when throttled
This commit is contained in:
parent
115fe04842
commit
c3891b6e00
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user