Skip to content

Commit

Permalink
Use no custom header APIs when header type isn't used (#40482)
Browse files Browse the repository at this point in the history
  • Loading branch information
alzimmermsft authored Jun 4, 2024
1 parent 83026f6 commit 83c2a2c
Show file tree
Hide file tree
Showing 23 changed files with 289 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,8 @@ public Mono<Response<Void>> createWithResponse(Map<String, String> metadata, Pub
Mono<Response<Void>> createWithResponse(Map<String, String> metadata, PublicAccessType accessType,
Context context) {
context = context == null ? Context.NONE : context;
return this.azureBlobStorage.getContainers().createWithResponseAsync(
containerName, null, metadata, accessType, null, blobContainerEncryptionScope, context)
.map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getContainers().createNoCustomHeadersWithResponseAsync(containerName, null,
metadata, accessType, null, blobContainerEncryptionScope, context);
}

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

return this.azureBlobStorage.getContainers().deleteWithResponseAsync(containerName, null,
return this.azureBlobStorage.getContainers().deleteNoCustomHeadersWithResponseAsync(containerName, null,
requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), null, context)
.map(response -> new SimpleResponse<>(response, null));
requestConditions.getIfUnmodifiedSince(), null, context);
}

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

return this.azureBlobStorage.getContainers().setMetadataWithResponseAsync(containerName, null,
requestConditions.getLeaseId(), metadata, requestConditions.getIfModifiedSince(), null, context)
.map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getContainers().setMetadataNoCustomHeadersWithResponseAsync(containerName, null,
requestConditions.getLeaseId(), metadata, requestConditions.getIfModifiedSince(), null, context);
}

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

return this.azureBlobStorage.getContainers().setAccessPolicyWithResponseAsync(
containerName, null, requestConditions.getLeaseId(), accessType, requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), null, identifiers, context)
.map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getContainers().setAccessPolicyNoCustomHeadersWithResponseAsync(containerName,
null, requestConditions.getLeaseId(), accessType, requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), null, identifiers, context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,8 @@ Mono<Response<Void>> setPropertiesWithResponse(BlobServiceProperties properties,
}
context = context == null ? Context.NONE : context;

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,10 @@ Mono<Response<Void>> sealWithResponse(AppendBlobSealOptions options, Context con
requestConditions = (requestConditions == null) ? new AppendBlobRequestConditions() : requestConditions;
context = context == null ? Context.NONE : context;

return this.azureBlobStorage.getAppendBlobs().sealWithResponseAsync(containerName, blobName, null, null,
requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
return this.azureBlobStorage.getAppendBlobs().sealNoCustomHeadersWithResponseAsync(containerName, blobName,
null, null, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
requestConditions.getIfNoneMatch(), requestConditions.getAppendPosition(),
context)
.map(response -> new SimpleResponse<>(response, null));
requestConditions.getIfNoneMatch(), requestConditions.getAppendPosition(), context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,22 +518,21 @@ public Mono<Response<Boolean>> existsWithResponse() {
}

Mono<Response<Boolean>> existsWithResponse(Context context) {
return this.getPropertiesWithResponse(null, context)
return this.getPropertiesWithResponseNoHeaders(context)
.map(cp -> (Response<Boolean>) new SimpleResponse<>(cp, true))
.onErrorResume(t -> t instanceof BlobStorageException
&& BlobErrorCode.BLOB_USES_CUSTOMER_SPECIFIED_ENCRYPTION
.equals(((BlobStorageException) t).getErrorCode()),
t -> {
HttpResponse response = ((BlobStorageException) t).getResponse();
.onErrorResume(BlobStorageException.class, e -> {
if (BlobErrorCode.BLOB_USES_CUSTOMER_SPECIFIED_ENCRYPTION.equals(e.getErrorCode())) {
HttpResponse response = e.getResponse();
return Mono.just(new SimpleResponse<>(response.getRequest(), response.getStatusCode(),
response.getHeaders(), true));
})
.onErrorResume(t -> t instanceof BlobStorageException && ((BlobStorageException) t).getStatusCode() == 404,
t -> {
HttpResponse response = ((BlobStorageException) t).getResponse();
} else if (e.getStatusCode() == 404) {
HttpResponse response = e.getResponse();
return Mono.just(new SimpleResponse<>(response.getRequest(), response.getStatusCode(),
response.getHeaders(), false));
});
} else {
return Mono.error(e);
}
});
}

/**
Expand Down Expand Up @@ -892,9 +891,8 @@ public Mono<Response<Void>> abortCopyFromUrlWithResponse(String copyId, String l
}

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

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

return this.azureBlobStorage.getBlobs().deleteWithResponseAsync(containerName, blobName, snapshot, versionId,
null, requestConditions.getLeaseId(), deleteBlobSnapshotOptions, requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, null, context)
.map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getBlobs().deleteNoCustomHeadersWithResponseAsync(containerName, blobName,
snapshot, versionId, null, requestConditions.getLeaseId(), deleteBlobSnapshotOptions,
requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(),
requestConditions.getIfMatch(), requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(),
null, null, context);
}

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

return this.azureBlobStorage.getBlobs().getPropertiesWithResponseAsync(
containerName, blobName, snapshot, versionId, null, requestConditions.getLeaseId(),
requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, customerProvidedKey, context)
return this.azureBlobStorage.getBlobs().getPropertiesWithResponseAsync(containerName, blobName, snapshot,
versionId, null, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, customerProvidedKey,
context)
.map(rb -> new SimpleResponse<>(rb, BlobPropertiesConstructorProxy
.create(new BlobPropertiesInternalGetProperties(rb.getDeserializedHeaders()))));
}

Mono<Response<Void>> getPropertiesWithResponseNoHeaders(Context context) {
context = context == null ? Context.NONE : context;

return this.azureBlobStorage.getBlobs().getPropertiesNoCustomHeadersWithResponseAsync(containerName, blobName,
snapshot, versionId, null, null, null, null, null, null, null, null, customerProvidedKey, context);
}

/**
* Changes a blob's HTTP header properties. if only one HTTP header is updated, the others will all be erased. In
* order to preserve existing values, they must be passed alongside the header being changed.
Expand Down Expand Up @@ -1895,11 +1900,10 @@ Mono<Response<Void>> setHttpHeadersWithResponse(BlobHttpHeaders headers, BlobReq
Context context) {
requestConditions = requestConditions == null ? new BlobRequestConditions() : requestConditions;

return this.azureBlobStorage.getBlobs().setHttpHeadersWithResponseAsync(
containerName, blobName, null, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
return this.azureBlobStorage.getBlobs().setHttpHeadersNoCustomHeadersWithResponseAsync(containerName, blobName,
null, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, headers, context)
.map(response -> new SimpleResponse<>(response, null));
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, headers, context);
}

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

return this.azureBlobStorage.getBlobs().setMetadataWithResponseAsync(
containerName, blobName, null, metadata, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
return this.azureBlobStorage.getBlobs().setMetadataNoCustomHeadersWithResponseAsync(containerName, blobName,
null, metadata, requestConditions.getLeaseId(), requestConditions.getIfModifiedSince(),
requestConditions.getIfUnmodifiedSince(), requestConditions.getIfMatch(),
requestConditions.getIfNoneMatch(), requestConditions.getTagsConditions(), null, customerProvidedKey,
encryptionScope, context)
.map(response -> new SimpleResponse<>(response, null));
encryptionScope, context);
}

/**
Expand Down Expand Up @@ -2103,9 +2106,9 @@ Mono<Response<Void>> setTagsWithResponse(BlobSetTagsOptions options, Context con
}
}
BlobTags t = new BlobTags().setBlobTagSet(tagList);
return this.azureBlobStorage.getBlobs().setTagsWithResponseAsync(containerName, blobName, null, versionId,
null, null, null, requestConditions.getTagsConditions(), requestConditions.getLeaseId(), t, context)
.map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getBlobs().setTagsNoCustomHeadersWithResponseAsync(containerName, blobName, null,
versionId, null, null, null, requestConditions.getTagsConditions(), requestConditions.getLeaseId(), t,
context);
}

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

return this.azureBlobStorage.getBlobs().setTierWithResponseAsync(
containerName, blobName, options.getTier(), snapshot, versionId, null,
options.getPriority(), null, options.getLeaseId(), options.getTagsConditions(), context)
.map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getBlobs().setTierNoCustomHeadersWithResponseAsync(containerName, blobName,
options.getTier(), snapshot, versionId, null, options.getPriority(), null, options.getLeaseId(),
options.getTagsConditions(), context);
}

/**
Expand Down Expand Up @@ -2331,8 +2333,8 @@ public Mono<Response<Void>> undeleteWithResponse() {
}

Mono<Response<Void>> undeleteWithResponse(Context context) {
return this.azureBlobStorage.getBlobs().undeleteWithResponseAsync(containerName, blobName, null,
null, context).map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getBlobs().undeleteNoCustomHeadersWithResponseAsync(containerName, blobName, null,
null, context);
}

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

Mono<Response<Void>> deleteImmutabilityPolicyWithResponse(Context context) {
context = context == null ? Context.NONE : context;
return this.azureBlobStorage.getBlobs().deleteImmutabilityPolicyWithResponseAsync(containerName, blobName,
null, null, context)
.map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getBlobs()
.deleteImmutabilityPolicyNoCustomHeadersWithResponseAsync(containerName, blobName, null, null, context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,13 @@ Mono<Response<Void>> releaseLeaseWithResponse(BlobReleaseLeaseOptions options, C
context = context == null ? Context.NONE : context;

if (this.isBlob) {
return this.client.getBlobs().releaseLeaseWithResponseAsync(containerName, blobName, this.leaseId, null,
requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(),
return this.client.getBlobs().releaseLeaseNoCustomHeadersWithResponseAsync(containerName, blobName,
this.leaseId, null, requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(),
requestConditions.getIfMatch(), requestConditions.getIfNoneMatch(),
requestConditions.getTagsConditions(), null,
context)
.map(response -> new SimpleResponse<>(response, null));
requestConditions.getTagsConditions(), null, context);
} else {
return this.client.getContainers().releaseLeaseWithResponseAsync(containerName, this.leaseId, null,
requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(),
null, context)
.map(response -> new SimpleResponse<>(response, null));
return this.client.getContainers().releaseLeaseNoCustomHeadersWithResponseAsync(containerName, this.leaseId,
null, requestConditions.getIfModifiedSince(), requestConditions.getIfUnmodifiedSince(), null, context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,11 +756,9 @@ Mono<Response<Void>> stageBlockWithResponse(String base64BlockId, BinaryData dat
Objects.requireNonNull(data, "data must not be null");
Objects.requireNonNull(data.getLength(), "data must have defined length");
context = context == null ? Context.NONE : context;
return this.azureBlobStorage.getBlockBlobs().stageBlockWithResponseAsync(containerName, blobName,
base64BlockId, data.getLength(), data, contentMd5, null, null,
leaseId, null, getCustomerProvidedKey(),
encryptionScope, context)
.map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getBlockBlobs().stageBlockNoCustomHeadersWithResponseAsync(containerName, blobName,
base64BlockId, data.getLength(), data, contentMd5, null, null, leaseId, null, getCustomerProvidedKey(),
encryptionScope, context);
}

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

return this.azureBlobStorage.getBlockBlobs().stageBlockFromURLWithResponseAsync(containerName, blobName,
options.getBase64BlockId(), 0, options.getSourceUrl(), sourceRange.toHeaderValue(), options.getSourceContentMd5(), null, null,
options.getLeaseId(), sourceRequestConditions.getIfModifiedSince(),
sourceRequestConditions.getIfUnmodifiedSince(), sourceRequestConditions.getIfMatch(),
sourceRequestConditions.getIfNoneMatch(), null, sourceAuth, getCustomerProvidedKey(),
encryptionScope, context)
.map(response -> new SimpleResponse<>(response, null));
return this.azureBlobStorage.getBlockBlobs().stageBlockFromURLNoCustomHeadersWithResponseAsync(containerName,
blobName, options.getBase64BlockId(), 0, options.getSourceUrl(), sourceRange.toHeaderValue(),
options.getSourceContentMd5(), null, null, options.getLeaseId(),
sourceRequestConditions.getIfModifiedSince(), sourceRequestConditions.getIfUnmodifiedSince(),
sourceRequestConditions.getIfMatch(), sourceRequestConditions.getIfNoneMatch(), null, sourceAuth,
getCustomerProvidedKey(), encryptionScope, context);
}

/**
Expand Down
Loading

0 comments on commit 83c2a2c

Please sign in to comment.