aliyun_oss_rs/object/
get_object_url.rs

1use crate::{
2    common::{CacheControl, ContentDisposition},
3    request::{Oss, OssRequest},
4};
5use http::Method;
6use std::net::IpAddr;
7use time::OffsetDateTime;
8
9/// Get the object's URL
10///
11/// Private objects can obtain a signed URL to download directly
12///
13/// See the [Alibaba Cloud documentation](https://help.aliyun.com/document_detail/31952.html) for details
14pub struct GetObjectUrl {
15    req: OssRequest,
16}
17impl GetObjectUrl {
18    pub(super) fn new(oss: Oss) -> Self {
19        GetObjectUrl {
20            req: OssRequest::new(oss, Method::GET),
21        }
22    }
23    /// Set IP information
24    ///
25    /// To allow a single IP, set `subnet_mask` to 32
26    ///
27    pub fn set_source_ip(mut self, source_ip: IpAddr, subnet_mask: u8) -> Self {
28        self.req.insert_query("x-oss-ac-source-ip", source_ip);
29        self.req
30            .insert_query("x-oss-ac-subnet-mask", subnet_mask.to_string());
31        self
32    }
33    /// Set VPC information
34    ///
35    pub fn set_vpc_id(mut self, vpc_id: impl ToString) -> Self {
36        self.req.insert_query("x-oss-ac-vpc-id", vpc_id);
37        self
38    }
39    /// Allow request forwarding
40    ///
41    /// Disabled by default
42    ///
43    pub fn forward_allow(mut self) -> Self {
44        self.req.insert_query("x-oss-ac-forward-allow", "true");
45        self
46    }
47    /// Set the response content-type
48    ///
49    pub fn set_response_mime(
50        mut self,
51        mime: impl ToString,
52        charset: Option<impl ToString>,
53    ) -> Self {
54        let mut mime_str = mime.to_string();
55        if let Some(charset) = charset {
56            mime_str.push_str(";charset=");
57            mime_str.push_str(&charset.to_string());
58        }
59        self.req.insert_query("response-content-type", mime_str);
60        self
61    }
62    /// Set the response cache-control
63    ///
64    pub fn set_response_cache_control(mut self, cache_control: CacheControl) -> Self {
65        self.req
66            .insert_query("response-cache-control", cache_control);
67        self
68    }
69    /// Set the response content-disposition
70    ///
71    pub fn set_response_content_disposition(
72        mut self,
73        content_disposition: ContentDisposition,
74    ) -> Self {
75        self.req
76            .insert_query("response-content-disposition", content_disposition);
77        self
78    }
79    /// Set a custom domain
80    ///
81    pub fn set_custom_domain(mut self, custom_domain: impl ToString, enable_https: bool) -> Self {
82        self.req.set_endpoint(custom_domain);
83        self.req.set_https(enable_https);
84        self
85    }
86    /// Generate the URL
87    ///
88    pub fn url(mut self, expires: OffsetDateTime) -> String {
89        self.req.query_sign(expires);
90        self.req.uri()
91    }
92}