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

View file

@ -38,11 +38,13 @@ type Options struct {
redirectIfExists string
}
var client = fasthttp.Client{
ReadTimeout: 10 * time.Second,
MaxConnDuration: 60 * time.Second,
MaxConnWaitTimeout: 1000 * time.Millisecond,
MaxConnsPerHost: 128 * 16, // TODO: adjust bottlenecks for best performance with Gitea!
func getFastHTTPClient(timeout time.Duration) *fasthttp.Client {
return &fasthttp.Client{
ReadTimeout: timeout,
MaxConnDuration: 60 * time.Second,
MaxConnWaitTimeout: 1000 * time.Millisecond,
MaxConnsPerHost: 128 * 16, // TODO: adjust bottlenecks for best performance with Gitea!
}
}
// Upstream requests a file from the Gitea API at GiteaRoot and writes it to the request context.
@ -89,10 +91,11 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaRoot, giteaAPIToken st
cachedResponse = cachedValue.(fileResponse)
} else {
req = fasthttp.AcquireRequest()
req.SetRequestURI(giteaRoot + giteaApiRepos + uri + "?access_token=" + giteaAPIToken)
req.SetRequestURI(giteaRoot + giteaApiRepos + uri)
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
res = fasthttp.AcquireResponse()
res.SetBodyStream(&strings.Reader{}, -1)
err = client.Do(req, res)
err = getFastHTTPClient(10*time.Second).Do(req, res)
}
log.Debug().Msg("acquisition")