aboutsummaryrefslogtreecommitdiff
path: root/src/http/ratelimiting.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/ratelimiting.rs')
-rw-r--r--src/http/ratelimiting.rs25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/http/ratelimiting.rs b/src/http/ratelimiting.rs
index bce9f12..a0023f6 100644
--- a/src/http/ratelimiting.rs
+++ b/src/http/ratelimiting.rs
@@ -47,7 +47,7 @@ use hyper::status::StatusCode;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::time::Duration;
-use std::{i64, str, thread};
+use std::{str, thread, i64};
use super::{HttpError, LightMethod};
use internal::prelude::*;
@@ -399,15 +399,16 @@ pub(crate) fn perform<'a, F>(route: Route, f: F) -> Result<Response>
let redo = if response.headers.get_raw("x-ratelimit-global").is_some() {
let _ = GLOBAL.lock().expect("global route lock poisoned");
- Ok(if let Some(retry_after) =
- parse_header(&response.headers, "retry-after")? {
- debug!("Ratelimited on route {:?} for {:?}ms", route, retry_after);
- thread::sleep(Duration::from_millis(retry_after as u64));
+ Ok(
+ if let Some(retry_after) = parse_header(&response.headers, "retry-after")? {
+ debug!("Ratelimited on route {:?} for {:?}ms", route, retry_after);
+ thread::sleep(Duration::from_millis(retry_after as u64));
- true
- } else {
- false
- })
+ true
+ } else {
+ false
+ },
+ )
} else {
lock.post_hook(&response, &route)
};
@@ -508,9 +509,9 @@ fn parse_header(headers: &Headers, header: &str) -> Result<Option<i64>> {
str::from_utf8(&header[0])
.map_err(|_| Error::Http(HttpError::RateLimitUtf8))
.and_then(|v| {
- v.parse::<i64>().map(|v| Some(v)).map_err(|_| {
- Error::Http(HttpError::RateLimitI64)
- })
+ v.parse::<i64>()
+ .map(|v| Some(v))
+ .map_err(|_| Error::Http(HttpError::RateLimitI64))
})
})
}