Set api client token statically, unrestrict client dynamically and download client nothing
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
@@ -23,12 +22,12 @@ import (
|
||||
)
|
||||
|
||||
type HTTPClient struct {
|
||||
token string
|
||||
client *http.Client
|
||||
maxRetries int
|
||||
timeoutSecs int
|
||||
rateLimitSleepSecs int
|
||||
backoff func(attempt int) time.Duration
|
||||
token atomic.Value
|
||||
dnsCache cmap.ConcurrentMap[string, string]
|
||||
hosts []string
|
||||
log *logutil.Logger
|
||||
@@ -53,6 +52,7 @@ func (e *DownloadErrorResponse) Error() string {
|
||||
}
|
||||
|
||||
func NewHTTPClient(
|
||||
token string,
|
||||
maxRetries int,
|
||||
timeoutSecs int,
|
||||
forceIPv6 bool,
|
||||
@@ -61,6 +61,7 @@ func NewHTTPClient(
|
||||
log *logutil.Logger,
|
||||
) *HTTPClient {
|
||||
client := HTTPClient{
|
||||
token: token,
|
||||
client: &http.Client{},
|
||||
maxRetries: maxRetries,
|
||||
timeoutSecs: timeoutSecs,
|
||||
@@ -127,14 +128,9 @@ func NewHTTPClient(
|
||||
return &client
|
||||
}
|
||||
|
||||
func (r *HTTPClient) SetToken(token string) {
|
||||
r.token.Store(token)
|
||||
}
|
||||
|
||||
func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
|
||||
token := r.token.Load()
|
||||
if token != nil && token.(string) != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+token.(string))
|
||||
if r.token != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+r.token)
|
||||
}
|
||||
|
||||
var resp *http.Response
|
||||
|
||||
Reference in New Issue
Block a user