azure_storage_blobs/blob/operations/
put_block_url.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::prelude::*;
use azure_core::{headers::*, prelude::*, RequestId, Url};
use azure_storage::{headers::consistency_from_headers, ConsistencyCRC64, ConsistencyMD5};
use time::OffsetDateTime;

operation! {
    PutBlockUrl,
    client: BlobClient,
    block_id: BlockId,
    url: Url,
    ?hash: Hash,
    ?range: Range,
    ?lease_id: LeaseId
}

impl PutBlockUrlBuilder {
    pub fn into_future(mut self) -> PutBlockUrl {
        Box::pin(async move {
            let mut url = self.client.url()?;

            self.block_id.append_to_url_query(&mut url);
            url.query_pairs_mut().append_pair("comp", "block");

            let mut headers = Headers::new();
            headers.insert(COPY_SOURCE, self.url.to_string());
            headers.add(self.lease_id);
            if let Some(range) = self.range {
                headers.insert(SOURCE_RANGE, format!("{range}"));
            }

            let mut request =
                BlobClient::finalize_request(url, azure_core::Method::Put, headers, None)?;

            let response = self.client.send(&mut self.context, &mut request).await?;
            PutBlockUrlResponse::from_headers(response.headers())
        })
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PutBlockUrlResponse {
    pub content_md5: Option<ConsistencyMD5>,
    pub content_crc64: Option<ConsistencyCRC64>,
    pub request_id: RequestId,
    pub date: OffsetDateTime,
    pub request_server_encrypted: bool,
}

impl PutBlockUrlResponse {
    pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<PutBlockUrlResponse> {
        let (content_md5, content_crc64) = consistency_from_headers(headers)?;
        let request_id = request_id_from_headers(headers)?;
        let date = date_from_headers(headers)?;
        let request_server_encrypted = request_server_encrypted_from_headers(headers)?;

        Ok(PutBlockUrlResponse {
            content_md5,
            content_crc64,
            request_id,
            date,
            request_server_encrypted,
        })
    }
}