aliyun_oss_rs/object/
get_symlink.rs

1use crate::{
2    Error,
3    error::normal_error,
4    request::{Oss, OssRequest},
5};
6use http::Method;
7use percent_encoding::percent_decode;
8
9/// Get the symlink
10///
11/// See the [Alibaba Cloud documentation](https://help.aliyun.com/document_detail/45146.html) for details
12pub struct GetSymlink {
13    req: OssRequest,
14}
15impl GetSymlink {
16    pub(super) fn new(oss: Oss) -> Self {
17        let mut req = OssRequest::new(oss, Method::GET);
18        req.insert_query("symlink", "");
19        GetSymlink { req }
20    }
21    /// Send the request
22    ///
23    pub async fn send(self) -> Result<String, Error> {
24        // Build the HTTP request
25        let response = self.req.send_to_oss()?.await?;
26        // Parse the response
27        let status_code = response.status();
28        match status_code {
29            code if code.is_success() => {
30                let target = response
31                    .headers()
32                    .get("x-oss-symlink-target")
33                    .map(|v| v.as_bytes())
34                    .unwrap_or_else(|| "".as_bytes());
35                let target_decode = percent_decode(target)
36                    .decode_utf8()
37                    .map_err(|_| Error::OssInvalidResponse(None))?;
38                Ok(target_decode.into_owned())
39            }
40            _ => Err(normal_error(response).await),
41        }
42    }
43}