Skip to content

Commit 49ee0b4

Browse files
authored
fix 304 (#22647)
1 parent c255d5c commit 49ee0b4

File tree

9 files changed

+825
-0
lines changed

9 files changed

+825
-0
lines changed

sdk/storage/Azure.Storage.Blobs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Added support for RequestConditions parameter validation. If a request condition is set for an API that doesn't support it, and ArguementException will be thrown.
1414
- This feature can be disabled with the environment variable "AZURE_STORAGE_DISABLE_REQUEST_CONDITIONS_VALIDATION" or the App Context switch "Azure.Storage.DisableRequestConditionsValidation".
1515
- Fixed bug where BlobBaseClient.DownloadStreamingAsync() won't correctly parse the LeaseStatus header.
16+
- Fixed bug where BlobBaseClient.DownloadContentAsync() fails on 304 response.
1617

1718
## 12.9.1 (2021-06-23)
1819
- Added optimization to unwrap encryption key once for DownloadTo and OpenRead when Client Side Encryption is enabled.

sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,13 @@ private async Task<Response<BlobDownloadInfo>> DownloadInternal(
946946
$"{nameof(BlobBaseClient)}.{nameof(Download)}",
947947
async,
948948
cancellationToken).ConfigureAwait(false);
949+
950+
// Return an exploding Response on 304
951+
if (response.IsUnavailable())
952+
{
953+
return response.GetRawResponse().AsNoBodyResponse<BlobDownloadInfo>();
954+
}
955+
949956
BlobDownloadStreamingResult blobDownloadStreamingResult = response.Value;
950957
BlobDownloadDetails blobDownloadDetails = blobDownloadStreamingResult.Details;
951958
return Response.FromValue(
@@ -1573,6 +1580,13 @@ private async Task<Response<BlobDownloadResult>> DownloadContentInternal(
15731580
operationName: $"{nameof(BlobBaseClient)}.{nameof(DownloadContent)}",
15741581
async: async,
15751582
cancellationToken: cancellationToken).ConfigureAwait(false);
1583+
1584+
// Return an exploding Response on 304
1585+
if (response.IsUnavailable())
1586+
{
1587+
return response.GetRawResponse().AsNoBodyResponse<BlobDownloadResult>();
1588+
}
1589+
15761590
using BlobDownloadStreamingResult blobDownloadStreamingResult = response.Value;
15771591
BinaryData data;
15781592
if (async)

sdk/storage/Azure.Storage.Blobs/tests/BlobBaseClientTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,72 @@ public async Task DownloadTo_Initial304()
15261526
Assert.AreEqual(304, result.Status);
15271527
}
15281528

1529+
[RecordedTest]
1530+
public async Task DownloadContent_Initial304()
1531+
{
1532+
await using DisposingContainer test = await GetTestContainerAsync();
1533+
1534+
// Upload a blob
1535+
var data = GetRandomBuffer(Constants.KB);
1536+
BlobClient blob = InstrumentClient(test.Container.GetBlobClient(GetNewBlobName()));
1537+
using (var stream = new MemoryStream(data))
1538+
{
1539+
await blob.UploadAsync(stream);
1540+
}
1541+
1542+
// Add conditions to cause a failure and ensure we don't explode
1543+
Response<BlobDownloadResult> result = await blob.DownloadContentAsync(
1544+
new BlobRequestConditions
1545+
{
1546+
IfModifiedSince = Recording.UtcNow
1547+
});
1548+
Assert.AreEqual(304, result.GetRawResponse().Status);
1549+
}
1550+
1551+
[RecordedTest]
1552+
public async Task DownloadStreaming_Initial304()
1553+
{
1554+
await using DisposingContainer test = await GetTestContainerAsync();
1555+
1556+
// Upload a blob
1557+
var data = GetRandomBuffer(Constants.KB);
1558+
BlobClient blob = InstrumentClient(test.Container.GetBlobClient(GetNewBlobName()));
1559+
using (var stream = new MemoryStream(data))
1560+
{
1561+
await blob.UploadAsync(stream);
1562+
}
1563+
1564+
// Add conditions to cause a failure and ensure we don't explode
1565+
Response<BlobDownloadStreamingResult> result = await blob.DownloadStreamingAsync(
1566+
conditions: new BlobRequestConditions
1567+
{
1568+
IfModifiedSince = Recording.UtcNow
1569+
});
1570+
Assert.AreEqual(304, result.GetRawResponse().Status);
1571+
}
1572+
1573+
[RecordedTest]
1574+
public async Task Download_Initial304()
1575+
{
1576+
await using DisposingContainer test = await GetTestContainerAsync();
1577+
1578+
// Upload a blob
1579+
var data = GetRandomBuffer(Constants.KB);
1580+
BlobClient blob = InstrumentClient(test.Container.GetBlobClient(GetNewBlobName()));
1581+
using (var stream = new MemoryStream(data))
1582+
{
1583+
await blob.UploadAsync(stream);
1584+
}
1585+
1586+
// Add conditions to cause a failure and ensure we don't explode
1587+
Response<BlobDownloadInfo> result = await blob.DownloadAsync(
1588+
conditions: new BlobRequestConditions
1589+
{
1590+
IfModifiedSince = Recording.UtcNow
1591+
});
1592+
Assert.AreEqual(304, result.GetRawResponse().Status);
1593+
}
1594+
15291595
[RecordedTest]
15301596
public async Task DownloadTo_ReplacedDuringDownload()
15311597
{

sdk/storage/Azure.Storage.Blobs/tests/SessionRecords/BlobBaseClientTests/DownloadContent_Initial304.json

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)