gitea auth only in header & gitea calls in own func

This commit is contained in:
6543 2021-12-15 06:17:37 +01:00
parent 4794318791
commit 06b6875f95
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
4 changed files with 62 additions and 26 deletions
server/upstream

View file

@ -5,6 +5,7 @@ import (
"net/url"
"path"
"strings"
"time"
"github.com/valyala/fasthttp"
@ -19,11 +20,11 @@ func CheckCanonicalDomain(targetOwner, targetRepo, targetBranch, actualDomain, m
func giteaRawContent(targetOwner, targetRepo, ref, giteaRoot, giteaAPIToken, resource string) ([]byte, error) {
req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(giteaRoot, giteaApiRepos, targetOwner, "/", targetRepo, "/raw/", resource, "?ref="+url.QueryEscape(ref)))
req.SetRequestURI(path.Join(giteaRoot, giteaApiRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref)))
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
res := fasthttp.AcquireResponse()
if err := client.Do(req, res); err != nil {
if err := getFastHTTPClient(10*time.Second).Do(req, res); err != nil {
return nil, err
}
if res.StatusCode() != fasthttp.StatusOK {
@ -46,7 +47,6 @@ func checkCanonicalDomain(targetOwner, targetRepo, targetBranch, actualDomain, m
}
}
} else {
body, err := giteaRawContent(giteaRoot, targetRepo, targetBranch, giteaRoot, giteaAPIToken, canonicalDomainConfig)
if err == nil {
for _, domain := range strings.Split(string(body), "\n") {