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
69
70
71
72
use reqwest::header::HeaderMap;
/// Provider-neutral presigned range-download plan.
#[derive(Debug, Clone)]
pub struct PresignedRangeDownloadPlan {
/// Known remote object size. When present, download prepare skips HEAD.
pub total_size: Option<u64>,
/// Optional dedicated HEAD URL.
pub head_url: Option<String>,
/// URL used for range GET requests.
pub range_url: String,
/// Optional range URL expiration timestamp in Unix seconds.
pub range_expires_at_unix_secs: Option<u64>,
/// Refresh threshold in seconds. Range URL is refreshed before a chunk when
/// `now + refresh_before_secs >= range_expires_at_unix_secs`.
pub refresh_before_secs: u64,
/// Headers added to HEAD requests.
pub head_headers: HeaderMap,
/// Headers added to range GET requests.
pub range_headers: HeaderMap,
}
impl PresignedRangeDownloadPlan {
/// Creates a plan using the same URL for range GET and optional HEAD.
pub fn new(range_url: impl Into<String>) -> Self {
Self {
total_size: None,
head_url: None,
range_url: range_url.into(),
range_expires_at_unix_secs: None,
refresh_before_secs: 60,
head_headers: HeaderMap::new(),
range_headers: HeaderMap::new(),
}
}
/// Sets known remote object size and enables HEAD skipping.
pub fn with_total_size(mut self, total_size: u64) -> Self {
self.total_size = Some(total_size);
self
}
/// Sets dedicated HEAD URL.
pub fn with_head_url(mut self, url: impl Into<String>) -> Self {
self.head_url = Some(url.into());
self
}
/// Sets range URL expiration timestamp in Unix seconds.
pub fn with_range_expires_at_unix_secs(mut self, expires_at_unix_secs: u64) -> Self {
self.range_expires_at_unix_secs = Some(expires_at_unix_secs);
self
}
/// Sets range URL refresh threshold in seconds.
pub fn with_refresh_before_secs(mut self, secs: u64) -> Self {
self.refresh_before_secs = secs;
self
}
/// Replaces HEAD headers.
pub fn with_head_headers(mut self, headers: HeaderMap) -> Self {
self.head_headers = headers;
self
}
/// Replaces range GET headers.
pub fn with_range_headers(mut self, headers: HeaderMap) -> Self {
self.range_headers = headers;
self
}
}