Skip to content

Commit 83c2a2c

Browse files
authored
Use no custom header APIs when header type isn't used (Azure#40482)
1 parent 83026f6 commit 83c2a2c

File tree

23 files changed

+289
-412
lines changed

23 files changed

+289
-412
lines changed

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobContainerAsyncClient.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ public Mono<Response<Void>> createWithResponse(Map<String, String> metadata, Pub
425425
Mono<Response<Void>> createWithResponse(Map<String, String> metadata, PublicAccessType accessType,
426426
Context context) {
427427
context = context == null ? Context.NONE : context;
428-
return this.azureBlobStorage.getContainers().createWithResponseAsync(
429-
containerName, null, metadata, accessType, null, blobContainerEncryptionScope, context)
430-
.map(response -> new SimpleResponse<>(response, null));
428+
return this.azureBlobStorage.getContainers().createNoCustomHeadersWithResponseAsync(containerName, null,
429+
metadata, accessType, null, blobContainerEncryptionScope, context);
431430
}
432431

433432
/**
@@ -573,10 +572,9 @@ Mono<Response<Void>> deleteWithResponse(BlobRequestConditions requestConditions,
573572
}
574573
context = context == null ? Context.NONE : context;
575574

576-
return this.azureBlobStorage.getContainers().deleteWithResponseAsync(containerName, null,
575+
return this.azureBlobStorage.getContainers().deleteNoCustomHeadersWithResponseAsync(containerName, null,
577576
requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
578-
requestConditions.getIfUnmodifiedSince(), null, context)
579-
.map(response -> new SimpleResponse<>(response, null));
577+
requestConditions.getIfUnmodifiedSince(), null, context);
580578
}
581579

582580
/**
@@ -799,9 +797,8 @@ Mono<Response<Void>> setMetadataWithResponse(Map<String, String> metadata,
799797
"If-Modified-Since is the only HTTP access condition supported for this API"));
800798
}
801799

802-
return this.azureBlobStorage.getContainers().setMetadataWithResponseAsync(containerName, null,
803-
requestConditions.getLeaseId(), metadata, requestConditions.getIfModifiedSince(), null, context)
804-
.map(response -> new SimpleResponse<>(response, null));
800+
return this.azureBlobStorage.getContainers().setMetadataNoCustomHeadersWithResponseAsync(containerName, null,
801+
requestConditions.getLeaseId(), metadata, requestConditions.getIfModifiedSince(), null, context);
805802
}
806803

807804
/**
@@ -990,10 +987,9 @@ OffsetDateTime.now will only give back milliseconds (more precise fields are zer
990987
}
991988
context = context == null ? Context.NONE : context;
992989

993-
return this.azureBlobStorage.getContainers().setAccessPolicyWithResponseAsync(
994-
containerName, null, requestConditions.getLeaseId(), accessType, requestConditions.getIfModifiedSince(),
995-
requestConditions.getIfUnmodifiedSince(), null, identifiers, context)
996-
.map(response -> new SimpleResponse<>(response, null));
990+
return this.azureBlobStorage.getContainers().setAccessPolicyNoCustomHeadersWithResponseAsync(containerName,
991+
null, requestConditions.getLeaseId(), accessType, requestConditions.getIfModifiedSince(),
992+
requestConditions.getIfUnmodifiedSince(), null, identifiers, context);
997993
}
998994

999995
/**

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceAsyncClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,8 @@ Mono<Response<Void>> setPropertiesWithResponse(BlobServiceProperties properties,
859859
}
860860
context = context == null ? Context.NONE : context;
861861

862-
return this.azureBlobStorage.getServices().setPropertiesWithResponseAsync(finalProperties, null, null, context)
863-
.map(response -> new SimpleResponse<>(response, null));
862+
return this.azureBlobStorage.getServices()
863+
.setPropertiesNoCustomHeadersWithResponseAsync(finalProperties, null, null, context);
864864
}
865865

866866
/**

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/specialized/AppendBlobAsyncClient.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,10 @@ Mono<Response<Void>> sealWithResponse(AppendBlobSealOptions options, Context con
669669
requestConditions = (requestConditions == null) ? new AppendBlobRequestConditions() : requestConditions;
670670
context = context == null ? Context.NONE : context;
671671

672-
return this.azureBlobStorage.getAppendBlobs().sealWithResponseAsync(containerName, blobName, null, null,
673-
requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
672+
return this.azureBlobStorage.getAppendBlobs().sealNoCustomHeadersWithResponseAsync(containerName, blobName,
673+
null, null, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
674674
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
675-
requestConditions.getIfNoneMatch(), requestConditions.getAppendPosition(),
676-
context)
677-
.map(response -> new SimpleResponse<>(response, null));
675+
requestConditions.getIfNoneMatch(), requestConditions.getAppendPosition(), context);
678676
}
679677

680678
/**

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/specialized/BlobAsyncClientBase.java

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -518,22 +518,21 @@ public Mono<Response<Boolean>> existsWithResponse() {
518518
}
519519

520520
Mono<Response<Boolean>> existsWithResponse(Context context) {
521-
return this.getPropertiesWithResponse(null, context)
521+
return this.getPropertiesWithResponseNoHeaders(context)
522522
.map(cp -> (Response<Boolean>) new SimpleResponse<>(cp, true))
523-
.onErrorResume(t -> t instanceof BlobStorageException
524-
&& BlobErrorCode.BLOB_USES_CUSTOMER_SPECIFIED_ENCRYPTION
525-
.equals(((BlobStorageException) t).getErrorCode()),
526-
t -> {
527-
HttpResponse response = ((BlobStorageException) t).getResponse();
523+
.onErrorResume(BlobStorageException.class, e -> {
524+
if (BlobErrorCode.BLOB_USES_CUSTOMER_SPECIFIED_ENCRYPTION.equals(e.getErrorCode())) {
525+
HttpResponse response = e.getResponse();
528526
return Mono.just(new SimpleResponse<>(response.getRequest(), response.getStatusCode(),
529527
response.getHeaders(), true));
530-
})
531-
.onErrorResume(t -> t instanceof BlobStorageException && ((BlobStorageException) t).getStatusCode() == 404,
532-
t -> {
533-
HttpResponse response = ((BlobStorageException) t).getResponse();
528+
} else if (e.getStatusCode() == 404) {
529+
HttpResponse response = e.getResponse();
534530
return Mono.just(new SimpleResponse<>(response.getRequest(), response.getStatusCode(),
535531
response.getHeaders(), false));
536-
});
532+
} else {
533+
return Mono.error(e);
534+
}
535+
});
537536
}
538537

539538
/**
@@ -892,9 +891,8 @@ public Mono<Response<Void>> abortCopyFromUrlWithResponse(String copyId, String l
892891
}
893892

894893
Mono<Response<Void>> abortCopyFromUrlWithResponse(String copyId, String leaseId, Context context) {
895-
return this.azureBlobStorage.getBlobs().abortCopyFromURLWithResponseAsync(
896-
containerName, blobName, copyId, null, leaseId, null, context)
897-
.map(response -> new SimpleResponse<>(response, null));
894+
return this.azureBlobStorage.getBlobs().abortCopyFromURLNoCustomHeadersWithResponseAsync(
895+
containerName, blobName, copyId, null, leaseId, null, context);
898896
}
899897

900898
/**
@@ -1675,11 +1673,11 @@ Mono<Response<Void>> deleteWithResponse(DeleteSnapshotsOptionType deleteBlobSnap
16751673
BlobRequestConditions requestConditions, Context context) {
16761674
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;
16771675

1678-
return this.azureBlobStorage.getBlobs().deleteWithResponseAsync(containerName, blobName, snapshot, versionId,
1679-
null, requestConditions.getLeaseId(), deleteBlobSnapshotOptions, requestConditions.getIfModifiedSince(),
1680-
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
1681-
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, null, context)
1682-
.map(response -> new SimpleResponse<>(response, null));
1676+
return this.azureBlobStorage.getBlobs().deleteNoCustomHeadersWithResponseAsync(containerName, blobName,
1677+
snapshot, versionId, null, requestConditions.getLeaseId(), deleteBlobSnapshotOptions,
1678+
requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(),
1679+
requestConditions.getIfMatch(), requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(),
1680+
null, null, context);
16831681
}
16841682

16851683
/**
@@ -1821,15 +1819,22 @@ Mono<Response<BlobProperties>> getPropertiesWithResponse(BlobRequestConditions r
18211819
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;
18221820
context = context == null ? Context.NONE : context;
18231821

1824-
return this.azureBlobStorage.getBlobs().getPropertiesWithResponseAsync(
1825-
containerName, blobName, snapshot, versionId, null, requestConditions.getLeaseId(),
1826-
requestConditions.getIfModifiedSince(),
1827-
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
1828-
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, customerProvidedKey, context)
1822+
return this.azureBlobStorage.getBlobs().getPropertiesWithResponseAsync(containerName, blobName, snapshot,
1823+
versionId, null, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
1824+
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
1825+
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, customerProvidedKey,
1826+
context)
18291827
.map(rb -> new SimpleResponse<>(rb, BlobPropertiesConstructorProxy
18301828
.create(new BlobPropertiesInternalGetProperties(rb.getDeserializedHeaders()))));
18311829
}
18321830

1831+
Mono<Response<Void>> getPropertiesWithResponseNoHeaders(Context context) {
1832+
context = context == null ? Context.NONE : context;
1833+
1834+
return this.azureBlobStorage.getBlobs().getPropertiesNoCustomHeadersWithResponseAsync(containerName, blobName,
1835+
snapshot, versionId, null, null, null, null, null, null, null, null, customerProvidedKey, context);
1836+
}
1837+
18331838
/**
18341839
* Changes a blob's HTTP header properties. if only one HTTP header is updated, the others will all be erased. In
18351840
* order to preserve existing values, they must be passed alongside the header being changed.
@@ -1895,11 +1900,10 @@ Mono<Response<Void>> setHttpHeadersWithResponse(BlobHttpHeaders headers, BlobReq
18951900
Context context) {
18961901
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;
18971902

1898-
return this.azureBlobStorage.getBlobs().setHttpHeadersWithResponseAsync(
1899-
containerName, blobName, null, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
1903+
return this.azureBlobStorage.getBlobs().setHttpHeadersNoCustomHeadersWithResponseAsync(containerName, blobName,
1904+
null, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
19001905
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
1901-
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, headers, context)
1902-
.map(response -> new SimpleResponse<>(response, null));
1906+
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, headers, context);
19031907
}
19041908

19051909
/**
@@ -1964,12 +1968,11 @@ Mono<Response<Void>> setMetadataWithResponse(Map<String, String> metadata, BlobR
19641968
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;
19651969
context = context == null ? Context.NONE : context;
19661970

1967-
return this.azureBlobStorage.getBlobs().setMetadataWithResponseAsync(
1968-
containerName, blobName, null, metadata, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
1971+
return this.azureBlobStorage.getBlobs().setMetadataNoCustomHeadersWithResponseAsync(containerName, blobName,
1972+
null, metadata, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
19691973
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
19701974
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, customerProvidedKey,
1971-
encryptionScope, context)
1972-
.map(response -> new SimpleResponse<>(response, null));
1975+
encryptionScope, context);
19731976
}
19741977

19751978
/**
@@ -2103,9 +2106,9 @@ Mono<Response<Void>> setTagsWithResponse(BlobSetTagsOptions options, Context con
21032106
}
21042107
}
21052108
BlobTags t = new BlobTags().setBlobTagSet(tagList);
2106-
return this.azureBlobStorage.getBlobs().setTagsWithResponseAsync(containerName, blobName, null, versionId,
2107-
null, null, null, requestConditions.getTagsConditions(), requestConditions.getLeaseId(), t, context)
2108-
.map(response -> new SimpleResponse<>(response, null));
2109+
return this.azureBlobStorage.getBlobs().setTagsNoCustomHeadersWithResponseAsync(containerName, blobName, null,
2110+
versionId, null, null, null, requestConditions.getTagsConditions(), requestConditions.getLeaseId(), t,
2111+
context);
21092112
}
21102113

21112114
/**
@@ -2277,10 +2280,9 @@ public Mono<Response<Void>> setAccessTierWithResponse(BlobSetAccessTierOptions o
22772280
Mono<Response<Void>> setTierWithResponse(BlobSetAccessTierOptions options, Context context) {
22782281
StorageImplUtils.assertNotNull("options", options);
22792282

2280-
return this.azureBlobStorage.getBlobs().setTierWithResponseAsync(
2281-
containerName, blobName, options.getTier(), snapshot, versionId, null,
2282-
options.getPriority(), null, options.getLeaseId(), options.getTagsConditions(), context)
2283-
.map(response -> new SimpleResponse<>(response, null));
2283+
return this.azureBlobStorage.getBlobs().setTierNoCustomHeadersWithResponseAsync(containerName, blobName,
2284+
options.getTier(), snapshot, versionId, null, options.getPriority(), null, options.getLeaseId(),
2285+
options.getTagsConditions(), context);
22842286
}
22852287

22862288
/**
@@ -2331,8 +2333,8 @@ public Mono<Response<Void>> undeleteWithResponse() {
23312333
}
23322334

23332335
Mono<Response<Void>> undeleteWithResponse(Context context) {
2334-
return this.azureBlobStorage.getBlobs().undeleteWithResponseAsync(containerName, blobName, null,
2335-
null, context).map(response -> new SimpleResponse<>(response, null));
2336+
return this.azureBlobStorage.getBlobs().undeleteNoCustomHeadersWithResponseAsync(containerName, blobName, null,
2337+
null, context);
23362338
}
23372339

23382340
/**
@@ -2772,9 +2774,8 @@ public Mono<Response<Void>> deleteImmutabilityPolicyWithResponse() {
27722774

27732775
Mono<Response<Void>> deleteImmutabilityPolicyWithResponse(Context context) {
27742776
context = context == null ? Context.NONE : context;
2775-
return this.azureBlobStorage.getBlobs().deleteImmutabilityPolicyWithResponseAsync(containerName, blobName,
2776-
null, null, context)
2777-
.map(response -> new SimpleResponse<>(response, null));
2777+
return this.azureBlobStorage.getBlobs()
2778+
.deleteImmutabilityPolicyNoCustomHeadersWithResponseAsync(containerName, blobName, null, null, context);
27782779
}
27792780

27802781
/**

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/specialized/BlobLeaseAsyncClient.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,13 @@ Mono<Response<Void>> releaseLeaseWithResponse(BlobReleaseLeaseOptions options, C
399399
context = context == null ? Context.NONE : context;
400400

401401
if (this.isBlob) {
402-
return this.client.getBlobs().releaseLeaseWithResponseAsync(containerName, blobName, this.leaseId, null,
403-
requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(),
402+
return this.client.getBlobs().releaseLeaseNoCustomHeadersWithResponseAsync(containerName, blobName,
403+
this.leaseId, null, requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(),
404404
requestConditions.getIfMatch(), requestConditions.getIfNoneMatch(),
405-
requestConditions.getTagsConditions(), null,
406-
context)
407-
.map(response -> new SimpleResponse<>(response, null));
405+
requestConditions.getTagsConditions(), null, context);
408406
} else {
409-
return this.client.getContainers().releaseLeaseWithResponseAsync(containerName, this.leaseId, null,
410-
requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(),
411-
null, context)
412-
.map(response -> new SimpleResponse<>(response, null));
407+
return this.client.getContainers().releaseLeaseNoCustomHeadersWithResponseAsync(containerName, this.leaseId,
408+
null, requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(), null, context);
413409
}
414410
}
415411

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/specialized/BlockBlobAsyncClient.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -756,11 +756,9 @@ Mono<Response<Void>> stageBlockWithResponse(String base64BlockId, BinaryData dat
756756
Objects.requireNonNull(data, "data must not be null");
757757
Objects.requireNonNull(data.getLength(), "data must have defined length");
758758
context = context == null ? Context.NONE : context;
759-
return this.azureBlobStorage.getBlockBlobs().stageBlockWithResponseAsync(containerName, blobName,
760-
base64BlockId, data.getLength(), data, contentMd5, null, null,
761-
leaseId, null, getCustomerProvidedKey(),
762-
encryptionScope, context)
763-
.map(response -> new SimpleResponse<>(response, null));
759+
return this.azureBlobStorage.getBlockBlobs().stageBlockNoCustomHeadersWithResponseAsync(containerName, blobName,
760+
base64BlockId, data.getLength(), data, contentMd5, null, null, leaseId, null, getCustomerProvidedKey(),
761+
encryptionScope, context);
764762
}
765763

766764
/**
@@ -881,13 +879,12 @@ Mono<Response<Void>> stageBlockFromUrlWithResponse(BlockBlobStageBlockFromUrlOpt
881879
String sourceAuth = options.getSourceAuthorization() == null
882880
? null : options.getSourceAuthorization().toString();
883881

884-
return this.azureBlobStorage.getBlockBlobs().stageBlockFromURLWithResponseAsync(containerName, blobName,
885-
options.getBase64BlockId(), 0, options.getSourceUrl(), sourceRange.toHeaderValue(), options.getSourceContentMd5(), null, null,
886-
options.getLeaseId(), sourceRequestConditions.getIfModifiedSince(),
887-
sourceRequestConditions.getIfUnmodifiedSince(), sourceRequestConditions.getIfMatch(),
888-
sourceRequestConditions.getIfNoneMatch(), null, sourceAuth, getCustomerProvidedKey(),
889-
encryptionScope, context)
890-
.map(response -> new SimpleResponse<>(response, null));
882+
return this.azureBlobStorage.getBlockBlobs().stageBlockFromURLNoCustomHeadersWithResponseAsync(containerName,
883+
blobName, options.getBase64BlockId(), 0, options.getSourceUrl(), sourceRange.toHeaderValue(),
884+
options.getSourceContentMd5(), null, null, options.getLeaseId(),
885+
sourceRequestConditions.getIfModifiedSince(), sourceRequestConditions.getIfUnmodifiedSince(),
886+
sourceRequestConditions.getIfMatch(), sourceRequestConditions.getIfNoneMatch(), null, sourceAuth,
887+
getCustomerProvidedKey(), encryptionScope, context);
891888
}
892889

893890
/**

0 commit comments

Comments
 (0)