fix: Always add authorization if a token is provided

This commit is contained in:
PapaTutuWawa 2024-02-04 13:40:34 +01:00
parent fbb80c622f
commit aaab500049

View File

@ -7,6 +7,7 @@ import (
"time"
"code.gitea.io/sdk/gitea"
log "github.com/sirupsen/logrus"
"git.polynom.me/rio/internal/dns"
)
@ -89,17 +90,19 @@ func NewGiteaClient(giteaUrl string, token string, giteaClient *gitea.Client) Gi
path,
branch,
)
log.Debugf("GetFile: Requesting '%s'", apiUrl)
client := &http.Client{}
req, err := http.NewRequest("GET", apiUrl, nil)
if since != nil {
sinceFormat := since.Format(time.RFC1123)
req.Header.Add("If-Modified-Since", sinceFormat)
// Add authentication, if we have a token
if token != "" {
req.Header.Add("Authorization", "token "+token)
}
}
// Add authentication, if we have a token
if token != "" {
req.Header.Add("Authorization", "token "+token)
}
resp, err := client.Do(req)
if err != nil {
return []byte{}, true, err