1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-03 15:02:35 +02:00

feature(httpReadFile): Add headers to download from github release assets (#4826)

This commit is contained in:
Googlom 2024-02-20 13:35:41 +05:00 committed by GitHub
parent bdc49e7be6
commit 150560db9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -382,7 +382,13 @@ func httpReadFile(name string, accessTokens map[string]string) (io.ReadCloser, e
var header http.Header
if len(accessTokens[u.Host]) > 0 {
client.SetOptions(piperhttp.ClientOptions{Token: fmt.Sprintf("token %v", accessTokens[u.Host])})
header = map[string][]string{"Accept": {"application/vnd.github.v3.raw"}}
if strings.Contains(u.Path, "releases/assets") {
// Assets download endpoint requires 'application/octet-stream' media type.
// See: https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#get-a-release-asset
header = map[string][]string{"Accept": {"application/octet-stream"}}
} else {
header = map[string][]string{"Accept": {"application/vnd.github.v3.raw"}}
}
}
response, err := client.SendRequest("GET", name, nil, header, nil)