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:
Kyle Sanderson 2023-12-29 14:49:22 -08:00 committed by GitHub
parent 2a4fb7750b
commit 3234f0d919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 537 additions and 391 deletions

View file

@ -12,6 +12,8 @@ import (
"net/http"
"net/url"
"time"
"github.com/autobrr/autobrr/pkg/sharedhttp"
)
type Client struct {
@ -23,7 +25,7 @@ type Client struct {
log *log.Logger
Http *http.Client
http *http.Client
}
type Options struct {
@ -43,8 +45,9 @@ func New(opts Options) *Client {
basicUser: opts.BasicUser,
basicPass: opts.BasicPass,
log: log.New(io.Discard, "", log.LstdFlags),
Http: &http.Client{
Timeout: time.Second * 60,
http: &http.Client{
Timeout: time.Second * 60,
Transport: sharedhttp.Transport,
},
}
@ -88,7 +91,7 @@ func (c *Client) AddFromUrl(ctx context.Context, r AddNzbRequest) (*AddFileRespo
req.SetBasicAuth(c.basicUser, c.basicPass)
}
res, err := c.Http.Do(req)
res, err := c.http.Do(req)
if err != nil {
return nil, err
}
@ -137,7 +140,7 @@ func (c *Client) Version(ctx context.Context) (*VersionResponse, error) {
req.SetBasicAuth(c.basicUser, c.basicPass)
}
res, err := c.Http.Do(req)
res, err := c.http.Do(req)
if err != nil {
return nil, err
}