From 3de3f3110c7d84adb295f7af88f0ce3afc333052 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 24 Jan 2024 12:05:00 +0100 Subject: [PATCH] feat(assest): use original content-encoding for uploaded to azure assets --- ee/backend/pkg/objectstorage/azure/azure.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ee/backend/pkg/objectstorage/azure/azure.go b/ee/backend/pkg/objectstorage/azure/azure.go index bbe9adb9d..37c9537dc 100644 --- a/ee/backend/pkg/objectstorage/azure/azure.go +++ b/ee/backend/pkg/objectstorage/azure/azure.go @@ -43,17 +43,21 @@ func NewStorage(cfg *config.ObjectsConfig) (objectstorage.ObjectStorage, error) }, nil } -func (s *storageImpl) Upload(reader io.Reader, key string, contentType string, compression objectstorage.CompressionType) error { +func (s *storageImpl) Upload(reader io.Reader, key string, contentType, contentEncoding string, compression objectstorage.CompressionType) error { cacheControl := "max-age=2628000, immutable, private" - var contentEncoding *string + var encoding *string switch compression { case objectstorage.Gzip: gzipStr := "gzip" - contentEncoding = &gzipStr + encoding = &gzipStr case objectstorage.Brotli: gzipStr := "br" - contentEncoding = &gzipStr + encoding = &gzipStr } + if contentEncoding != "" { + encoding = &contentEncoding + } + // Remove leading slash to avoid empty folder creation if strings.HasPrefix(key, "/") { key = key[1:] @@ -61,7 +65,7 @@ func (s *storageImpl) Upload(reader io.Reader, key string, contentType string, c _, err := s.client.UploadStream(context.Background(), s.container, key, reader, &azblob.UploadStreamOptions{ HTTPHeaders: &blob.HTTPHeaders{ BlobCacheControl: &cacheControl, - BlobContentEncoding: contentEncoding, + BlobContentEncoding: encoding, BlobContentType: &contentType, }, Tags: s.tags,