This commit is contained in:
6543 2022-05-16 00:45:24 +02:00
parent ec7fcca0f5
commit 6234889495
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
2 changed files with 4 additions and 22 deletions

View file

@ -9,8 +9,6 @@ import (
"github.com/valyala/fasthttp"
"github.com/valyala/fastjson"
"codeberg.org/codeberg/pages/server/shared"
)
const giteaAPIRepos = "/api/v1/repos/"
@ -46,7 +44,7 @@ func (client *Client) GiteaRawContent(targetOwner, targetRepo, ref, resource str
req.Header.Set(fasthttp.HeaderAuthorization, client.giteaAPIToken)
res := fasthttp.AcquireResponse()
if err := shared.GetFastHTTPClient(10*time.Second).Do(req, res); err != nil {
if err := getFastHTTPClient(10*time.Second).Do(req, res); err != nil {
return nil, err
}
if res.StatusCode() != fasthttp.StatusOK {
@ -56,7 +54,7 @@ func (client *Client) GiteaRawContent(targetOwner, targetRepo, ref, resource str
}
func (client *Client) ServeRawContent(uri string) (*fasthttp.Response, error) {
fastClient := shared.GetFastHTTPClient(10 * time.Second)
fastClient := getFastHTTPClient(10 * time.Second)
req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, uri))
@ -69,7 +67,7 @@ func (client *Client) ServeRawContent(uri string) (*fasthttp.Response, error) {
}
func (client *Client) GiteaGetRepoBranchTimestamp(repoOwner, repoName, branchName string) (time.Time, error) {
fastClient := shared.GetFastHTTPClient(5 * time.Second)
fastClient := getFastHTTPClient(5 * time.Second)
req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, repoOwner, repoName, "branches", branchName))
@ -86,7 +84,7 @@ func (client *Client) GiteaGetRepoBranchTimestamp(repoOwner, repoName, branchNam
}
func (client *Client) GiteaGetRepoDefaultBranch(repoOwner, repoName string) (string, error) {
fastClient := shared.GetFastHTTPClient(5 * time.Second)
fastClient := getFastHTTPClient(5 * time.Second)
req := fasthttp.AcquireRequest()
req.SetRequestURI(path.Join(client.giteaRoot, giteaAPIRepos, repoOwner, repoName))

View file

@ -1,16 +0,0 @@
package shared
import (
"time"
"github.com/valyala/fasthttp"
)
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!
}
}