aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-18 09:58:32 -0800
committerAustin Hellyer <[email protected]>2016-11-18 10:09:09 -0800
commitdecd8e4eca52c6623499df593f484b4cde861213 (patch)
tree81894b43da05ae40bf316cf10b216880e9c0108d /src/client
parentAllow Id/u64 equality comparisons (diff)
downloadserenity-decd8e4eca52c6623499df593f484b4cde861213.tar.xz
serenity-decd8e4eca52c6623499df593f484b4cde861213.zip
Ratelimiting: don't attempt to RL for None
Some routes, mostly user-specific ones, do not have ratelimit headers. So when specifying the `Route::None` variant, do not attempt to treat it as its own bucket, and instead ignore ratelimiting for it.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/http/ratelimiting.rs32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/client/http/ratelimiting.rs b/src/client/http/ratelimiting.rs
index 00d6813..3518bdc 100644
--- a/src/client/http/ratelimiting.rs
+++ b/src/client/http/ratelimiting.rs
@@ -124,8 +124,10 @@ pub fn perform<'a, F>(route: Route, f: F) -> Result<Response>
// - then, perform the request
global.pre_hook();
- if let Some(route) = ROUTES.lock().expect("routes poisoned").get_mut(&route) {
- route.pre_hook();
+ if route != Route::None {
+ if let Some(route) = ROUTES.lock().expect("routes poisoned").get_mut(&route) {
+ route.pre_hook();
+ }
}
let response = try!(super::retry(&f));
@@ -144,18 +146,20 @@ pub fn perform<'a, F>(route: Route, f: F) -> Result<Response>
// so check if it did from the value of the 'x-ratelimit-limit'
// header. If the limit was 5 and is now 7, add 2 to the 'remaining'
- let redo = if response.headers.get_raw("x-ratelimit-global").is_some() {
- global.post_hook(&response)
- } else {
- ROUTES.lock()
- .expect("routes poisoned")
- .entry(route)
- .or_insert_with(RateLimit::default)
- .post_hook(&response)
- };
-
- if redo.unwrap_or(false) {
- continue;
+ if route != Route::None {
+ let redo = if response.headers.get_raw("x-ratelimit-global").is_some() {
+ global.post_hook(&response)
+ } else {
+ ROUTES.lock()
+ .expect("routes poisoned")
+ .entry(route)
+ .or_insert_with(RateLimit::default)
+ .post_hook(&response)
+ };
+
+ if redo.unwrap_or(false) {
+ continue;
+ }
}
return Ok(response);