From decd8e4eca52c6623499df593f484b4cde861213 Mon Sep 17 00:00:00 2001 From: Austin Hellyer Date: Fri, 18 Nov 2016 09:58:32 -0800 Subject: 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. --- src/client/http/ratelimiting.rs | 32 ++++++++++++++++++-------------- 1 file 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 // - 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 // 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); -- cgit v1.2.3