diff options
| author | Tom Christie | 2014-09-11 20:43:44 +0100 | 
|---|---|---|
| committer | Tom Christie | 2014-09-11 20:43:44 +0100 | 
| commit | 19b8f779de82fa4737b37fb4359145af0b07a56c (patch) | |
| tree | 09e3d8201501db7af2a01d30e476979a59bac4aa | |
| parent | bf52d04f4c370d6917599d26c84b73124d5ef366 (diff) | |
| download | django-rest-framework-19b8f779de82fa4737b37fb4359145af0b07a56c.tar.bz2 | |
Throttles now use Retry-After header and no longer support the custom style
| -rw-r--r-- | docs/api-guide/throttling.md | 2 | ||||
| -rw-r--r-- | rest_framework/views.py | 1 | ||||
| -rw-r--r-- | tests/test_throttling.py | 6 | 
3 files changed, 3 insertions, 6 deletions
| diff --git a/docs/api-guide/throttling.md b/docs/api-guide/throttling.md index 832304f1..16a7457b 100644 --- a/docs/api-guide/throttling.md +++ b/docs/api-guide/throttling.md @@ -178,6 +178,8 @@ To create a custom throttle, override `BaseThrottle` and implement `.allow_reque  Optionally you may also override the `.wait()` method.  If implemented, `.wait()` should return a recommended number of seconds to wait before attempting the next request, or `None`.  The `.wait()` method will only be called if `.allow_request()` has previously returned `False`. +If the `.wait()` method is implemented and the request is throttled, then a `Retry-After` header will be included in the response. +  ## Example  The following is an example of a rate throttle, that will randomly throttle 1 in every 10 requests. diff --git a/rest_framework/views.py b/rest_framework/views.py index 3b7b1c16..cd394b2d 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -62,7 +62,6 @@ def exception_handler(exc):          if getattr(exc, 'auth_header', None):              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}, diff --git a/tests/test_throttling.py b/tests/test_throttling.py index 7b696f07..cc36a004 100644 --- a/tests/test_throttling.py +++ b/tests/test_throttling.py @@ -109,7 +109,7 @@ class ThrottlingTests(TestCase):      def ensure_response_header_contains_proper_throttle_field(self, view, expected_headers):          """ -        Ensure the response returns an X-Throttle field with status and next attributes +        Ensure the response returns an Retry-After field with status and next attributes          set properly.          """          request = self.factory.get('/') @@ -117,10 +117,8 @@ class ThrottlingTests(TestCase):              self.set_throttle_timer(view, timer)              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): @@ -173,13 +171,11 @@ class ThrottlingTests(TestCase):          self.assertFalse(hasattr(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)          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) | 
