X-Throttled: Expires in x sec
This is an idea Tom came up with some time ago which I remembered just now.
Add an X-Throttled field to to the response of a throttled request.
This can be implemented with less then 3 lines of code I think, because the ErrorResponse class takes header fields as kwargs.
Ideally any throttling header ought to indicate 2 things.
- Success or failure
- A recommended delay before the next request. (Issued both on success and failure)
Eg. If the throttle is '3/sec':
First request is made: 'X-Throttle: status=SUCCESS; next=0.3333 sec' Next request is immediately made: 'X-Throttle: status=SUCCESS; next=0.5 sec' Next request is immediately made: 'X-Throttle: status=SUCCESS; next=1.0 sec' Next request is immediately made: 'X-Throttle: status=FAILURE; next=1.0 sec'
Cool! I'll pick up this one. First write some tests, then do the implementation.
I'm not really sure where the logic would live for responses to requests which have a throttle but were successfull. As I see it now; the dispatch() method of the View class would have to be tweaked. So that check_permissions() can return a value. Or the check_permissions() method can preset a header field on the View object or so. So that later on when the response will be rendered, the header can be inserted. But that would make things less obvious I guess.
Yeah. Prob need something like a .headers attribute on the View instance, and an add_header() method too.
On 13 June 2011 16:07, markotibold < [email protected]>wrote:
I'm not really sure where he logic would live for responses to requests which have a throttle but were successfull. As I see it now; the dispath() method of the View class would have to be tweaked. So that check_permissions() can return a value. Or the check_permissions() method can preset a header field on the View object or so. So that later on when the response will be rendered, the header can be inserted. But that would make things less obvious I guess.
Reply to this email directly or view it on GitHub:
https://github.com/tomchristie/django-rest-framework/issues/28#issuecomment-1359412
Implemented. The commits can be found on my repo at BitBucket.