Validate copy sources with HEAD instead of downloading the blob - #2680
Validate copy sources with HEAD instead of downloading the blob#2680Andrew Gaul (gaul) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR optimizes blob copy-source validation in Azurite by switching from a metadata GET (which Azurite currently serves as a full blob download) to a bodiless HEAD request, avoiding unnecessary data transfer and preventing axios decompression failures when the source declares Content-Encoding: gzip over non-gzip bytes.
Changes:
- Update copy-source validation to use
HEAD(Get Blob Properties) and retry withGET ?comp=metadataonly when needed, with axios decompression disabled on the retry. - Add a SAS-based regression test ensuring copy succeeds when the source declares
Content-Encoding: gzipbut the payload is not gzipped. - Document the behavior change in
ChangeLog.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/blob/sas.test.ts | Adds regression coverage for copy with misleading Content-Encoding: gzip on the source blob. |
| src/blob/handlers/BlobHandler.ts | Switches copy-source validation to HEAD, with a conditional GET ?comp=metadata retry to preserve error details and avoid decompression issues. |
| ChangeLog.md | Notes the optimization/fix in the upcoming release section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await blob2.beginCopyFromURL(blob1.url); | ||
|
|
||
| const properties = await blob2.getProperties(); |
|
Andrew Gaul (@gaul) , could you please refresh your PR with main, and address the review comments if any to move this PR forward. |
startCopyFromURL and copyFromURL validate the copy source by fetching <source>?comp=metadata through axios. Azurite serves that request as a full Blob_Download (issue Azure#646), so every validated copy downloaded the entire source only to discard it, and a source blob declaring Content-Encoding: gzip over bytes that are not really gzip made axios decompression fail and turned every copy of that blob into a 500. Validate with a bodiless HEAD (Get Blob Properties) request instead. Error details live only in response bodies, and reading an archived source must fail the copy like the download did, so those cases repeat the request as the previous comp=metadata GET, now with axios decompression disabled. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
beginCopyFromURL resolves once the poller is created, not when the copy finishes, so poll to completion like the neighboring tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
e601d9a to
8d754f9
Compare
Done. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/blob/handlers/BlobHandler.ts:744
- The archive-tier special-case here forces a GET
?comp=metadataeven when the HEAD succeeds. This validation helper doesn’t have the destinationtieroption available, so it can incorrectly block scenarios that the metadata store explicitly allows (e.g., same-account copy from an Archive blob when a destination tier is specified), and it also relies on?comp=metadatabehaving like a download to fail (butBlobHandler.getProperties()handlescomp=metadataas a 200 and does not enforce Archive restrictions).
Consider limiting the retry GET to non-200 responses (auth/404/etc.) and let the actual copy path enforce Archive semantics based on the real copy options.
if (
validationResponse.status !== 200 ||
validationResponse.headers["x-ms-access-tier"] === "Archive"
) {
// Error details live only in response bodies, and reading an
Re: the suppressed comment on
So the archive-tier check is load-bearing rather than redundant. HEAD returns 200 for an archived source, so without the special case an archived source would pass validation where it previously failed. On the concern that this can block a same-account copy from an Archive blob when a destination tier is specified: that's an accurate description of the behavior, but it is pre-existing rather than introduced by this PR. There is a genuine inconsistency in that area worth noting separately: |
startCopyFromURL and copyFromURL validate the copy source by fetching?comp=metadata through axios. Azurite serves that request as a full Blob_Download (issue #646), so every validated copy downloaded the entire source only to discard it, and a source blob declaring Content-Encoding: gzip over bytes that are not really gzip made axios decompression fail and turned every copy of that blob into a 500.
Validate with a bodiless HEAD (Get Blob Properties) request instead. Error details live only in response bodies, and reading an archived source must fail the copy like the download did, so those cases repeat the request as the previous comp=metadata GET, now with axios decompression disabled.