From 2b868320462ef30059235eae6ecf45fe9e0aee6f Mon Sep 17 00:00:00 2001 From: Joey Riches Date: Fri, 8 Dec 2023 19:39:56 +0000 Subject: [PATCH 1/2] builder/source/simple: Disable compression when downloading artifacts Generally causing more issues than it solves. It's usefulness is also pretty debatable when we're downloading pre-compressed artifacts. Resolves https://github.com/getsolus/packages/issues/989. --- builder/source/simple.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/builder/source/simple.go b/builder/source/simple.go index f26482c..0181ca3 100644 --- a/builder/source/simple.go +++ b/builder/source/simple.go @@ -21,6 +21,7 @@ import ( "crypto/sha256" "encoding/hex" "log/slog" + "net/http" "net/url" "os" "path/filepath" @@ -137,7 +138,17 @@ func (s *SimpleSource) download(destination string) error { req.SetChecksum(sha256.New(), sum, false) } - resp := grab.NewClient().Do(req) + // Keep go-grab defaults but also disable compression + // https://github.com/cavaliergopher/grab/blob/v3.0.1/v3/client.go#L53 + tr := &http.Transport{ + DisableCompression: true, + Proxy: http.ProxyFromEnvironment, + } + + client := grab.NewClient() + client.HTTPClient = &http.Client{Transport: tr} + + resp := client.Do(req) // Setup our progress bar pbar := pb.Start64(resp.Size()) From 7e30196ecc122252223936c2039a37e51eb5dbb0 Mon Sep 17 00:00:00 2001 From: Joey Riches Date: Tue, 12 Dec 2023 11:16:13 +0000 Subject: [PATCH 2/2] builder/source/simple: Initialize our own grab client Instead of initializing a default `NewClient()` Co-authored-by: Silke Hofstra --- builder/source/simple.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/builder/source/simple.go b/builder/source/simple.go index 0181ca3..993fb08 100644 --- a/builder/source/simple.go +++ b/builder/source/simple.go @@ -138,16 +138,18 @@ func (s *SimpleSource) download(destination string) error { req.SetChecksum(sha256.New(), sum, false) } - // Keep go-grab defaults but also disable compression - // https://github.com/cavaliergopher/grab/blob/v3.0.1/v3/client.go#L53 - tr := &http.Transport{ - DisableCompression: true, - Proxy: http.ProxyFromEnvironment, + // Create a client with compression disabled. + // See: https://github.com/cavaliergopher/grab/blob/v3.0.1/v3/client.go#L53 + client := &grab.Client{ + UserAgent: "solbuild", + HTTPClient: &http.Client{ + Transport: &http.Transport{ + DisableCompression: true, + Proxy: http.ProxyFromEnvironment, + }, + }, } - client := grab.NewClient() - client.HTTPClient = &http.Client{Transport: tr} - resp := client.Do(req) // Setup our progress bar