ISSUE-9507: ADD `application/gzip,application/octet-stream` accept header when downloading chart

Signed-off-by: Matt Clegg <m@cle.gg>
pull/13034/head
Matt Clegg 1 year ago
parent 7a7782478b
commit fff3547f9c
No known key found for this signature in database
GPG Key ID: 4103D2455B460CD0

@ -97,6 +97,8 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven
return "", nil, err return "", nil, err
} }
c.Options = append(c.Options, getter.WithAcceptHeader("application/gzip,application/octet-stream"))
data, err := g.Get(u.String(), c.Options...) data, err := g.Get(u.String(), c.Options...)
if err != nil { if err != nil {
return "", nil, err return "", nil, err

@ -38,6 +38,7 @@ type options struct {
unTar bool unTar bool
insecureSkipVerifyTLS bool insecureSkipVerifyTLS bool
plainHTTP bool plainHTTP bool
acceptHeader string
username string username string
password string password string
passCredentialsAll bool passCredentialsAll bool
@ -60,6 +61,13 @@ func WithURL(url string) Option {
} }
} }
// WithAcceptHeader sets the request's Accept header as some REST APIs serve multiple content types
func WithAcceptHeader(header string) Option {
return func(opts *options) {
opts.acceptHeader = header
}
}
// WithBasicAuth sets the request's Authorization header to use the provided credentials // WithBasicAuth sets the request's Authorization header to use the provided credentials
func WithBasicAuth(username, password string) Option { func WithBasicAuth(username, password string) Option {
return func(opts *options) { return func(opts *options) {

@ -53,6 +53,10 @@ func (g *HTTPGetter) get(href string) (*bytes.Buffer, error) {
return nil, err return nil, err
} }
if g.opts.acceptHeader != "" {
req.Header.Set("Accept", g.opts.acceptHeader)
}
req.Header.Set("User-Agent", version.GetUserAgent()) req.Header.Set("User-Agent", version.GetUserAgent())
if g.opts.userAgent != "" { if g.opts.userAgent != "" {
req.Header.Set("User-Agent", g.opts.userAgent) req.Header.Set("User-Agent", g.opts.userAgent)

Loading…
Cancel
Save