From feb5635181eb12a6e3516172a3f5af06a3bc93e1 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 30 Sep 2022 13:44:27 +0000 Subject: pkg/asset: don't set encoding by default It causes web browsers to decompress archives in place, which makes it more confusing for the users since the file extension remains in place. The only exception is html coverage reports, adjust the code to handle that. --- pkg/asset/storage.go | 6 +----- pkg/asset/type.go | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/asset/storage.go b/pkg/asset/storage.go index e790732bd..0b008b744 100644 --- a/pkg/asset/storage.go +++ b/pkg/asset/storage.go @@ -112,6 +112,7 @@ func (storage *Storage) uploadFileStream(reader io.Reader, assetType dashapi.Ass req := &uploadRequest{ savePath: path, contentType: typeDescr.ContentType, + contentEncoding: typeDescr.ContentEncoding, preserveExtension: typeDescr.preserveExtension, } if req.contentType == "" { @@ -287,10 +288,6 @@ func xzCompressor(req *uploadRequest, if !req.preserveExtension { newReq.savePath = fmt.Sprintf("%s.xz", newReq.savePath) } - // "gz" contentEncoding is not really supported so far, so let's just set contentType. - if newReq.contentType == "" { - newReq.contentType = "application/x-xz" - } resp, err := next(&newReq) if err != nil { return nil, err @@ -342,7 +339,6 @@ func gzipCompressor(req *uploadRequest, if !req.preserveExtension { newReq.savePath = fmt.Sprintf("%s.gz", newReq.savePath) } - newReq.contentEncoding = "gzip" resp, err := next(&newReq) if err != nil { return nil, err diff --git a/pkg/asset/type.go b/pkg/asset/type.go index 1fd218da8..e88198266 100644 --- a/pkg/asset/type.go +++ b/pkg/asset/type.go @@ -12,6 +12,7 @@ type TypeDescription struct { AllowMultiple bool GetTitle QueryTypeTitle ContentType string + ContentEncoding string ReportingPrio int // the smaller, the higher the asset is on the list during reporting NoReporting bool customCompressor Compressor @@ -44,6 +45,7 @@ var assetTypes = map[dashapi.AssetType]*TypeDescription{ GetTitle: constTitle("coverage report(html)"), AllowMultiple: true, ContentType: "text/html", + ContentEncoding: "gzip", // We do want to decompress than right in the browser. NoReporting: true, customCompressor: gzipCompressor, preserveExtension: true, -- cgit mrf-deployment