1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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)
}