hammer-plug icon indicating copy to clipboard operation
hammer-plug copied to clipboard

Set retry-after header in default on_deny

Open mathiasose opened this issue 6 years ago • 1 comments

This is very much a draft PR, I couldn't get the tests to run locally so I have no idea if it works as-is or needs some more work. Need some help from a maintainer to get this ready.


From MDN:

The Retry-After response HTTP header indicates how long the user agent should wait before making a follow-up request. (...) When sent with a 429 (Too Many Requests) response, this indicates how long to wait before making a new request.

This seems pretty easy to do in the on_deny handler if we pass scale as an option. Since retry-after is usually given in seconds we do integer division on the ms value, then cast it to a string and set it as the header. Done! In the same vein we can also make limit another option that custom handlers can use if they want.

mathiasose avatar Sep 04 '19 11:09 mathiasose

Awesome! Yeah I think this feature makes sense. I'd be happy to merge with a few basic tests. I can take over from there and write more tests and documentation.

Thanks! :tada: :two_hearts:

JuneKelly avatar Oct 21 '19 22:10 JuneKelly