mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-04 13:54:08 +00:00
fix timeout issue of gitea sdk client
This commit is contained in:
parent
cce656ec4e
commit
2cd77be1f2
1 changed files with 17 additions and 6 deletions
|
@ -49,6 +49,7 @@ const (
|
|||
|
||||
type Client struct {
|
||||
sdkClient *gitea.Client
|
||||
sdkFileClient *gitea.Client
|
||||
responseCache cache.ICache
|
||||
|
||||
giteaRoot string
|
||||
|
@ -68,8 +69,6 @@ func NewClient(cfg config.ForgeConfig, respCache cache.ICache) (*Client, error)
|
|||
}
|
||||
giteaRoot := strings.TrimSuffix(rootURL.String(), "/")
|
||||
|
||||
stdClient := http.Client{Timeout: 10 * time.Second}
|
||||
|
||||
forbiddenMimeTypes := make(map[string]bool, len(cfg.ForbiddenMimeTypes))
|
||||
for _, mimeType := range cfg.ForbiddenMimeTypes {
|
||||
forbiddenMimeTypes[mimeType] = true
|
||||
|
@ -80,15 +79,27 @@ func NewClient(cfg config.ForgeConfig, respCache cache.ICache) (*Client, error)
|
|||
defaultMimeType = "application/octet-stream"
|
||||
}
|
||||
|
||||
sdk, err := gitea.NewClient(
|
||||
sdkClient, err := gitea.NewClient(
|
||||
giteaRoot,
|
||||
gitea.SetHTTPClient(&stdClient),
|
||||
gitea.SetHTTPClient(&http.Client{Timeout: 10 * time.Second}),
|
||||
gitea.SetToken(cfg.Token),
|
||||
gitea.SetUserAgent("pages-server/"+version.Version),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sdkFileClient, err := gitea.NewClient(
|
||||
giteaRoot,
|
||||
gitea.SetHTTPClient(&http.Client{Timeout: 1 * time.Hour}),
|
||||
gitea.SetToken(cfg.Token),
|
||||
gitea.SetUserAgent("pages-server/"+version.Version),
|
||||
)
|
||||
|
||||
return &Client{
|
||||
sdkClient: sdk,
|
||||
sdkClient: sdkClient,
|
||||
sdkFileClient: sdkFileClient,
|
||||
responseCache: respCache,
|
||||
|
||||
giteaRoot: giteaRoot,
|
||||
|
@ -154,7 +165,7 @@ func (client *Client) ServeRawContent(ctx *context.Context, targetOwner, targetR
|
|||
}
|
||||
log.Trace().Msg("file not in cache")
|
||||
// not in cache, open reader via gitea api
|
||||
reader, resp, err := client.sdkClient.GetFileReader(targetOwner, targetRepo, ref, resource, client.supportLFS)
|
||||
reader, resp, err := client.sdkFileClient.GetFileReader(targetOwner, targetRepo, ref, resource, client.supportLFS)
|
||||
if resp != nil {
|
||||
switch resp.StatusCode {
|
||||
case http.StatusOK:
|
||||
|
|
Loading…
Add table
Reference in a new issue