azure_storage_blobs/blob/operations/
set_properties.rs

1use crate::{blob::BlobProperties, prelude::*};
2use azure_core::prelude::*;
3use azure_core::{
4    headers::{
5        date_from_headers, etag_from_headers, request_id_from_headers, server_from_headers, Headers,
6    },
7    Method, RequestId,
8};
9use time::OffsetDateTime;
10
11operation! {
12    SetProperties,
13    client: BlobClient,
14    ?if_modified_since: IfModifiedSinceCondition,
15    ?if_match: IfMatchCondition,
16    ?if_tags: IfTags,
17    ?lease_id: LeaseId,
18    ?cache_control: BlobCacheControl,
19    ?content_type: BlobContentType,
20    ?content_encoding: BlobContentEncoding,
21    ?content_language: BlobContentLanguage,
22    ?content_disposition: BlobContentDisposition,
23    ?content_md5: BlobContentMD5
24}
25
26impl SetPropertiesBuilder {
27    #[must_use]
28    pub fn set_from_blob_properties(self, blob_properties: BlobProperties) -> Self {
29        let mut s = self;
30
31        if let Some(cc) = blob_properties.cache_control {
32            s = s.cache_control(cc);
33        }
34        if !blob_properties.content_type.is_empty() {
35            s = s.content_type(blob_properties.content_type);
36        }
37        if let Some(ce) = blob_properties.content_encoding {
38            s = s.content_encoding(ce);
39        }
40        if let Some(cl) = blob_properties.content_language {
41            s = s.content_language(cl);
42        }
43        if let Some(cd) = blob_properties.content_disposition {
44            s = s.content_disposition(cd);
45        }
46        if let Some(cmd5) = blob_properties.content_md5 {
47            s = s.content_md5(cmd5);
48        }
49        s
50    }
51
52    pub fn into_future(mut self) -> SetProperties {
53        Box::pin(async move {
54            let mut url = self.client.url()?;
55
56            url.query_pairs_mut().append_pair("comp", "properties");
57
58            let mut headers = Headers::new();
59            headers.add(self.lease_id);
60            headers.add(self.cache_control);
61            headers.add(self.content_type);
62            headers.add(self.content_encoding);
63            headers.add(self.content_language);
64            headers.add(self.content_disposition);
65            headers.add(self.content_md5);
66            headers.add(self.if_modified_since);
67            headers.add(self.if_match);
68            headers.add(self.if_tags);
69
70            let mut request = BlobClient::finalize_request(url, Method::Put, headers, None)?;
71
72            let response = self.client.send(&mut self.context, &mut request).await?;
73            response.headers().try_into()
74        })
75    }
76}
77
78#[derive(Debug, Clone)]
79pub struct SetPropertiesResponse {
80    pub request_id: RequestId,
81    pub etag: String,
82    pub server: String,
83    pub date: OffsetDateTime,
84}
85
86impl TryFrom<&Headers> for SetPropertiesResponse {
87    type Error = azure_core::Error;
88
89    fn try_from(headers: &Headers) -> Result<Self, Self::Error> {
90        Ok(SetPropertiesResponse {
91            request_id: request_id_from_headers(headers)?,
92            etag: etag_from_headers(headers)?,
93            server: server_from_headers(headers)?,
94            date: date_from_headers(headers)?,
95        })
96    }
97}