Storage - Content validation content-length override#49226
Storage - Content validation content-length override#49226gunjansingh-msft wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Storage structured-message decoding path to override Content-Length on decoded responses (so callers see the decoded payload size), while preserving the original wire size in a new x-ms-original-content-length header and surfacing that value in Blob download headers.
Changes:
- Update
DecodedResponseto return adjusted headers with overriddenContent-Lengthand addedx-ms-original-content-length. - Update
StorageContentValidationDecoderPolicyto pass both original and decoded content lengths intoDecodedResponse. - Add
originalContentLengthsupport to Blob download headers and expand unit tests to validate the new header behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/storage/azure-storage-common/src/test/java/com/azure/storage/common/policy/DecodedResponseTests.java | Updates and expands tests to assert Content-Length override and preservation of the original length. |
| sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/StorageContentValidationDecoderPolicy.java | Reads x-ms-structured-content-length and passes original/decoded lengths into the decoded response wrapper. |
| sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/DecodedResponse.java | Implements header adjustment logic for decoded responses (overrides Content-Length, adds x-ms-original-content-length). |
| sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/Constants.java | Introduces constants for x-ms-original-content-length. |
| sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/BlobDownloadHeaders.java | Exposes originalContentLength on the public download headers model. |
| sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/models/BlobsDownloadHeaders.java | Adds parsing/storage for the new x-ms-original-content-length response header in the generated implementation model. |
Comments suppressed due to low confidence (1)
sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/models/BlobsDownloadHeaders.java:1628
- The newly added
getXMsOriginalContentLength/setXMsOriginalContentLengthaccessors are missing the@Generatedannotation, while surrounding accessors in this AutoRest-generated model are consistently annotated. Consider adding@Generatedfor consistency and to keep generated-code tooling behavior uniform.
* Get the xMsOriginalContentLength property: The wire size of the encoded structured message body before decoding.
*
* @return the xMsOriginalContentLength value.
*/
public Long getXMsOriginalContentLength() {
ibrandes
left a comment
There was a problem hiding this comment.
good direction on DecodedResponse + policy! Content-Length should match the decoded stream, using x-ms-structured-content-length. please avoid hand-editing autorest BlobsDownloadHeaders and adding a public getOriginalContentLength() backed by a synthetic x-ms-original-content-length; that reads like a service header and will regen badly. we can defer its exposure as a public api, like Alan mentioned originally.
…e/content-validation-content-length-override
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
sdk/storage/azure-storage-common/src/test/java/com/azure/storage/common/policy/StorageContentValidationDecoderPolicyTests.java:160
HttpResponseshould be closed (try-with-resources) afterpipeline.send(...).block()to avoid resource leaks; this test currently doesn't close the response.
HttpRequest request = new HttpRequest(HttpMethod.GET, "https://example.blob.core.windows.net/c/b");
HttpResponse response = pipeline.send(request, Context.NONE).block();
assertNotNull(response);
assertEquals(String.valueOf(encodedLen), response.getHeaders().getValue(HttpHeaderName.CONTENT_LENGTH));
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
ibrandes
left a comment
There was a problem hiding this comment.
lgtm! please fix CI errors before merging :)
No description provided.