Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[page-blob] introduce IfMatch header to put request #1850

Open
wants to merge 1 commit into
base: legacy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/storage_blobs/src/blob/operations/put_page_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ operation! {
?metadata: Metadata,
?tags: Tags,
?lease_id: LeaseId,
?if_match: IfMatchCondition,
?sequence_number: SequenceNumber
}

Expand All @@ -30,6 +31,7 @@ impl PutPageBlobBuilder {
headers.add(self.content_encoding);
headers.add(self.content_language);
headers.add(self.content_disposition);
headers.add(self.if_match);
headers.add(self.tags);
if let Some(metadata) = &self.metadata {
for m in metadata.iter() {
Expand Down
37 changes: 36 additions & 1 deletion sdk/storage_blobs/tests/page_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,46 @@ async fn put_page_blob() {

blob.put_page_blob(1024 * 64)
.content_type("text/plain")
.metadata(metadata)
.metadata(metadata.clone())
.await
.unwrap();

// CreateIfNotExists should fail if the page blob exists.
// This behavior is controlled through IfMatch conditions.
let res = blob
.put_page_blob(1024 * 64)
.content_type("text/plain")
.metadata(metadata.clone())
.if_match(IfMatchCondition::NotMatch(String::from("*")))
.await;
match res {
Ok(_) => {
assert!(false, "If-match condition is not being honored.");
}
Err(ref e) => {
let http_error = e
.as_http_error()
.expect("Violating if-Match condition should return an HTTP error");
assert_eq!(
azure_core::StatusCode::Conflict,
http_error.status(),
"Violating if-Match condition should return 409, Conflict"
);
}
}
trace!("created {:?}", blob_name);

// simulate Create a new page_blob with CreateIfNotExists.
let ifmatch_blob_name = "page-blob-ifmatch.txt";
let blob_client = container.blob_client(ifmatch_blob_name);
blob_client
.put_page_blob(1024 * 64)
.content_type("text/plain")
.metadata(metadata.clone())
.if_match(IfMatchCondition::NotMatch(String::from("*")))
.await
.unwrap();
trace!("created {:?}", ifmatch_blob_name);
}

fn initialize() -> BlobServiceClient {
Expand Down