use std::str;
use std::str::FromStr;
use hyper::header::{ ETag, Headers, LastModified, UserAgent };
pub fn has_github_hookshot(head: &Headers) -> bool {
head.get::<UserAgent>()
.map_or(false, |user_agent| {
user_agent.starts_with("GitHub-Hookshot")
})
}
pub fn etag(head: &Headers) -> Option<ETag> {
head.get::<ETag>()
.map(|tag| tag.to_owned())
}
pub fn last_modified(head: &Headers) -> Option<LastModified> {
head.get::<LastModified>()
.map(|modified| modified.to_owned())
}
pub fn rate_limit_remaining(head: &Headers) -> Option<u32> {
head.get_raw("X-RateLimit-Remaining")
.map(|limit| {
u32::from_str(
str::from_utf8(limit.one()
.unwrap_or(&[]))
.unwrap_or("")
).ok()
})
.unwrap_or(None)
}
pub fn rate_limit(head: &Headers) -> Option<u32> {
head.get_raw("X-RateLimit-Limit")
.map(|limit| {
u32::from_str(
str::from_utf8(limit.one()
.unwrap_or(&[]))
.unwrap_or("")
).ok()
})
.unwrap_or(None)
}
pub fn rate_limit_reset(head: &Headers) -> Option<u32> {
head.get_raw("X-RateLimit-Reset")
.map(|limit| {
u32::from_str(
str::from_utf8(limit.one()
.unwrap_or(&[]))
.unwrap_or("")
).ok()
})
.unwrap_or(None)
}