mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
refactor(http): implement shared transport and clients (#1288)
* fix(http): flip to a shared transport and clients * nice threads * that is terrible * fake uri for magnet * lazy locking * why bother with r's * flip magic params to struct * refactor(http-clients): use separate clients with shared transport * refactor(http-clients): add missing license header * refactor(http-clients): defer and fix errors --------- Co-authored-by: ze0s <ze0s@riseup.net>
This commit is contained in:
parent
2a4fb7750b
commit
3234f0d919
48 changed files with 537 additions and 391 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/errors"
|
||||
"github.com/autobrr/autobrr/pkg/sharedhttp"
|
||||
|
||||
goversion "github.com/hashicorp/go-version"
|
||||
)
|
||||
|
@ -72,6 +73,8 @@ type Checker struct {
|
|||
Owner string
|
||||
Repo string
|
||||
CurrentVersion string
|
||||
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
func NewChecker(owner, repo, currentVersion string) *Checker {
|
||||
|
@ -79,6 +82,10 @@ func NewChecker(owner, repo, currentVersion string) *Checker {
|
|||
Owner: owner,
|
||||
Repo: repo,
|
||||
CurrentVersion: currentVersion,
|
||||
httpClient: &http.Client{
|
||||
Timeout: time.Second * 30,
|
||||
Transport: sharedhttp.Transport,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,12 +100,11 @@ func (c *Checker) get(ctx context.Context) (*Release, error) {
|
|||
req.Header.Set("Accept", "application/vnd.github.v3+json")
|
||||
req.Header.Set("User-Agent", c.buildUserAgent())
|
||||
|
||||
client := http.DefaultClient
|
||||
|
||||
resp, err := client.Do(req)
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue