mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 06:16:58 +00:00
gitea auth only in header & gitea calls in own func
This commit is contained in:
parent
4794318791
commit
06b6875f95
4 changed files with 62 additions and 26 deletions
|
@ -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")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue