diff options
| author | Dmitry Mukhin | 2014-04-07 20:31:12 +0400 | 
|---|---|---|
| committer | Dmitry Mukhin | 2014-04-07 20:31:12 +0400 | 
| commit | c3891b6e00daa7a92cca1c88599e046f72926bb4 (patch) | |
| tree | 201120791360e16fa8fdea1ce688223801ce09ed | |
| parent | 115fe04842b58226b9fa29069b95af7df62b046a (diff) | |
| download | django-rest-framework-c3891b6e00daa7a92cca1c88599e046f72926bb4.tar.bz2 | |
set Retry-After header when throttled
| -rw-r--r-- | rest_framework/exceptions.py | 2 | ||||
| -rw-r--r-- | rest_framework/tests/test_throttling.py | 4 | ||||
| -rw-r--r-- | rest_framework/views.py | 1 | 
3 files changed, 6 insertions, 1 deletions
| diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index 5f774a9f..389032bd 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -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: diff --git a/rest_framework/tests/test_throttling.py b/rest_framework/tests/test_throttling.py index 41bff692..b5ae02cd 100644 --- a/rest_framework/tests/test_throttling.py +++ b/rest_framework/tests/test_throttling.py @@ -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): diff --git a/rest_framework/views.py b/rest_framework/views.py index a2668f2c..d6ccb301 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -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, | 
