Skip to content

Storage - Content validation content-length override#49226

Open
gunjansingh-msft wants to merge 9 commits into
feature/storage/content-validationfrom
feature/storage/content-validation-content-length-override
Open

Storage - Content validation content-length override#49226
gunjansingh-msft wants to merge 9 commits into
feature/storage/content-validationfrom
feature/storage/content-validation-content-length-override

Conversation

@gunjansingh-msft
Copy link
Copy Markdown
Member

@gunjansingh-msft gunjansingh-msft commented May 20, 2026

No description provided.

@github-actions github-actions Bot added the Storage Storage Service (Queues, Blobs, Files) label May 20, 2026
@ibrandes ibrandes requested a review from Copilot May 20, 2026 06:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DecodedResponse to return adjusted headers with overridden Content-Length and added x-ms-original-content-length.
  • Update StorageContentValidationDecoderPolicy to pass both original and decoded content lengths into DecodedResponse.
  • Add originalContentLength support 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 / setXMsOriginalContentLength accessors are missing the @Generated annotation, while surrounding accessors in this AutoRest-generated model are consistently annotated. Consider adding @Generated for 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() {

Copy link
Copy Markdown
Member

@ibrandes ibrandes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ibrandes ibrandes changed the title content length override changes Storage - Content validation content-length override May 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • HttpResponse should be closed (try-with-resources) after pipeline.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>
Copy link
Copy Markdown
Member

@ibrandes ibrandes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! please fix CI errors before merging :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Storage Storage Service (Queues, Blobs, Files)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants