aliyun_oss_rs/bucket/
get_bucket_referer.rs

1use crate::{
2    Error,
3    common::body_to_bytes,
4    error::normal_error,
5    request::{Oss, OssRequest},
6};
7use http::Method;
8
9use super::RefererConfiguration;
10
11/// Retrieve the referer configuration of a bucket.
12///
13/// See the [Alibaba Cloud documentation](https://help.aliyun.com/zh/oss/developer-reference/getbucketreferer) for details.
14pub struct GetBucketReferer {
15    req: OssRequest,
16}
17
18impl GetBucketReferer {
19    pub(super) fn new(oss: Oss) -> Self {
20        let mut req = OssRequest::new(oss, Method::GET);
21        req.insert_query("referer", "");
22        GetBucketReferer { req }
23    }
24
25    /// Send the request and return the parsed configuration.
26    pub async fn send(self) -> Result<RefererConfiguration, Error> {
27        let response = self.req.send_to_oss()?.await?;
28        match response.status() {
29            code if code.is_success() => {
30                let bytes = body_to_bytes(response.into_body()).await?;
31                let config: RefererConfiguration = serde_xml_rs::from_reader(bytes.as_ref())
32                    .map_err(|_| Error::OssInvalidResponse(Some(bytes)))?;
33                Ok(config)
34            }
35            _ => Err(normal_error(response).await),
36        }
37    }
38}