azure_storage_blobs/blob/operations/
put_block_list.rs1use crate::prelude::*;
2#[cfg(feature = "md5")]
3use azure_core::base64;
4use azure_core::{headers::*, prelude::*, RequestId};
5use azure_storage::{headers::content_md5_from_headers_optional, ConsistencyMD5};
6use bytes::Bytes;
7use time::OffsetDateTime;
8
9operation! {
10 PutBlockList,
11 client: BlobClient,
12 block_list: BlockList,
13 ?content_type: BlobContentType,
14 ?content_encoding: BlobContentEncoding,
15 ?content_language: BlobContentLanguage,
16 ?content_disposition: BlobContentDisposition,
17 ?content_md5: BlobContentMD5,
18 ?metadata: Metadata,
19 ?access_tier: AccessTier,
20 ?tags: Tags,
21 ?lease_id: LeaseId,
22 ?if_modified_since: IfModifiedSinceCondition,
23 ?if_match: IfMatchCondition,
24 ?if_tags: IfTags
25}
26
27impl PutBlockListBuilder {
28 pub fn into_future(mut self) -> PutBlockList {
29 Box::pin(async move {
30 let mut url = self.client.url()?;
31
32 url.query_pairs_mut().append_pair("comp", "blocklist");
33
34 let body = self.block_list.to_xml();
35 let body_bytes = Bytes::from(body);
36
37 #[cfg(feature = "md5")]
40 let md5 = {
41 let hash = md5::compute(&body_bytes);
42 base64::encode(hash.0)
43 };
44
45 let mut headers = Headers::new();
46 #[cfg(feature = "md5")]
47 headers.insert(CONTENT_MD5, &md5);
48 headers.add(self.content_type);
49 headers.add(self.content_encoding);
50 headers.add(self.content_language);
51 headers.add(self.content_disposition);
52 headers.add(self.content_md5);
53 headers.add(self.tags);
54 if let Some(metadata) = &self.metadata {
55 for m in metadata.iter() {
56 headers.add(m);
57 }
58 }
59 headers.add(self.access_tier);
60 headers.add(self.lease_id);
61 headers.add(self.if_modified_since);
62 headers.add(self.if_match);
63 headers.add(self.if_tags);
64
65 let mut request = BlobClient::finalize_request(
66 url,
67 azure_core::Method::Put,
68 headers,
69 Some(body_bytes.into()),
70 )?;
71
72 let response = self.client.send(&mut self.context, &mut request).await?;
73 PutBlockListResponse::from_headers(response.headers())
74 })
75 }
76}
77
78#[derive(Debug, Clone, PartialEq, Eq)]
79pub struct PutBlockListResponse {
80 pub etag: String,
81 pub last_modified: OffsetDateTime,
82 pub content_md5: Option<ConsistencyMD5>,
83 pub request_id: RequestId,
84 pub date: OffsetDateTime,
85 pub request_server_encrypted: bool,
86}
87
88impl PutBlockListResponse {
89 pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<PutBlockListResponse> {
90 let etag = etag_from_headers(headers)?;
91 let last_modified = last_modified_from_headers(headers)?;
92 let content_md5 = content_md5_from_headers_optional(headers)?;
93 let request_id = request_id_from_headers(headers)?;
94 let date = date_from_headers(headers)?;
95 let request_server_encrypted = request_server_encrypted_from_headers(headers)?;
96
97 Ok(PutBlockListResponse {
98 etag,
99 last_modified,
100 content_md5,
101 request_id,
102 date,
103 request_server_encrypted,
104 })
105 }
106}