Add network test
This commit is contained in:
@@ -24,23 +24,18 @@ import (
|
||||
)
|
||||
|
||||
type HTTPClient struct {
|
||||
client *http.Client
|
||||
maxRetries int
|
||||
timeoutSecs int
|
||||
backoff func(attempt int) time.Duration
|
||||
bearerToken string
|
||||
supportIPv6 bool
|
||||
cfg config.ConfigInterface
|
||||
ipv6 cmap.ConcurrentMap[string, string]
|
||||
ipv6Hosts []string
|
||||
log *logutil.Logger
|
||||
client *http.Client
|
||||
maxRetries int
|
||||
timeoutSecs int
|
||||
backoff func(attempt int) time.Duration
|
||||
bearerToken string
|
||||
isDownloadClient bool
|
||||
cfg config.ConfigInterface
|
||||
ipv6 cmap.ConcurrentMap[string, string]
|
||||
ipv6Hosts []string
|
||||
log *logutil.Logger
|
||||
}
|
||||
|
||||
// {
|
||||
// "error": "infringing_file",
|
||||
// "error_code": 35
|
||||
// }
|
||||
|
||||
type ApiErrorResponse struct {
|
||||
Message string `json:"error"`
|
||||
Code int `json:"error_code"`
|
||||
@@ -54,20 +49,20 @@ func NewHTTPClient(
|
||||
token string,
|
||||
maxRetries int,
|
||||
timeoutSecs int,
|
||||
supportIPv6 bool,
|
||||
isDownloadClient bool,
|
||||
cfg config.ConfigInterface,
|
||||
log *logutil.Logger,
|
||||
) *HTTPClient {
|
||||
client := HTTPClient{
|
||||
bearerToken: token,
|
||||
client: &http.Client{},
|
||||
maxRetries: maxRetries,
|
||||
timeoutSecs: timeoutSecs,
|
||||
backoff: backoffFunc,
|
||||
supportIPv6: supportIPv6,
|
||||
cfg: cfg,
|
||||
ipv6: cmap.New[string](),
|
||||
log: log,
|
||||
bearerToken: token,
|
||||
client: &http.Client{},
|
||||
maxRetries: maxRetries,
|
||||
timeoutSecs: timeoutSecs,
|
||||
backoff: backoffFunc,
|
||||
isDownloadClient: isDownloadClient,
|
||||
cfg: cfg,
|
||||
ipv6: cmap.New[string](),
|
||||
log: log,
|
||||
}
|
||||
|
||||
var dialer proxy.Dialer = &net.Dialer{
|
||||
@@ -217,7 +212,7 @@ func (r *HTTPClient) Do(req *http.Request) (*http.Response, error) {
|
||||
|
||||
func (r *HTTPClient) replaceWithIPv6Host(req *http.Request) {
|
||||
// don't replace host if IPv6 is not supported or not forced
|
||||
if !r.supportIPv6 || !r.cfg.ShouldForceIPv6() {
|
||||
if !r.isDownloadClient || !r.cfg.ShouldForceIPv6() {
|
||||
return
|
||||
}
|
||||
// this host should be replaced
|
||||
|
||||
Reference in New Issue
Block a user