mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +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
|
@ -4,7 +4,6 @@
|
|||
package porla
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
|
@ -12,6 +11,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/jsonrpc"
|
||||
"github.com/autobrr/autobrr/pkg/sharedhttp"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -62,20 +62,17 @@ func NewClient(cfg Config) *Client {
|
|||
c.timeout = time.Duration(cfg.Timeout) * time.Second
|
||||
}
|
||||
|
||||
c.http = &http.Client{
|
||||
Timeout: c.timeout,
|
||||
}
|
||||
|
||||
customTransport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
if cfg.TLSSkipVerify {
|
||||
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
||||
httpClient := &http.Client{
|
||||
Timeout: c.timeout,
|
||||
Transport: customTransport,
|
||||
Transport: sharedhttp.Transport,
|
||||
}
|
||||
|
||||
if cfg.TLSSkipVerify {
|
||||
httpClient.Transport = sharedhttp.TransportTLSInsecure
|
||||
}
|
||||
|
||||
c.http = httpClient
|
||||
|
||||
token := cfg.AuthToken
|
||||
|
||||
if !strings.HasPrefix(token, "Bearer ") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue