Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set content type and no-cache headers to blob publishing #8373

Merged
merged 2 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using System;
using System.Threading;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Build.CloudTestTasks;
#if !NET472_OR_GREATER
using Microsoft.DotNet.Maestro.Client.Models;
#endif
Expand Down Expand Up @@ -52,7 +54,11 @@ public async Task PublishAssetAsync(string file, string blobPath, PushOptions op

try
{
await blobClient.UploadAsync(file);
BlobUploadOptions blobUploadOptions = new()
{
HttpHeaders = AzureStorageUtils.GetBlobHeadersByExtension(file)
riarenas marked this conversation as resolved.
Show resolved Hide resolved
};
await blobClient.UploadAsync(file, blobUploadOptions);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ namespace Microsoft.DotNet.Build.CloudTestTasks
{
public class AzureStorageUtils
{
private readonly Dictionary<string, string> MimeMappings = new Dictionary<string, string>()
private static readonly Dictionary<string, string> MimeMappings = new Dictionary<string, string>()
{
{".svg", "image/svg+xml"},
{".version", "text/plain"}
};

private readonly Dictionary<string, string> CacheMappings = new Dictionary<string, string>()
private static readonly Dictionary<string, string> CacheMappings = new Dictionary<string, string>()
{
{".svg", "no-cache"}
};
Expand Down Expand Up @@ -138,7 +138,7 @@ public async Task<bool> CheckIfBlobExistsAsync(string blobPath) =>
await GetBlob(blobPath).ExistsAsync().ConfigureAwait(false);


private BlobHttpHeaders GetBlobHeadersByExtension(string filePath)
public static BlobHttpHeaders GetBlobHeadersByExtension(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
Expand Down