Support both socks and http proxies
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/pkg/hosts"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
http_dialer "github.com/mwitkow/go-http-dialer"
|
||||
"golang.org/x/net/proxy"
|
||||
|
||||
cmap "github.com/orcaman/concurrent-map/v2"
|
||||
@@ -119,12 +120,11 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host
|
||||
log.Errorf("Failed to parse proxy URL: %v", err)
|
||||
return nil
|
||||
}
|
||||
proxyDialer, err := proxy.FromURL(proxyURL, dialer)
|
||||
dialer, err = proxyDialer(proxyURL)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to create proxy dialer: %v", err)
|
||||
return nil
|
||||
}
|
||||
dialer = proxyDialer
|
||||
}
|
||||
|
||||
if cfg.ShouldForceIPv6() {
|
||||
@@ -245,3 +245,15 @@ func (r *HTTPClient) replaceHostIfNeeded(req *http.Request) {
|
||||
req.URL.Host = newHost
|
||||
}
|
||||
}
|
||||
|
||||
func proxyDialer(proxyURL *url.URL) (proxy.Dialer, error) {
|
||||
if proxyURL.Scheme == "http" || proxyURL.Scheme == "https" {
|
||||
// Create a new HTTP proxy dialer
|
||||
httpProxyDialer := http_dialer.New(proxyURL)
|
||||
return httpProxyDialer, nil
|
||||
} else if proxyURL.Scheme == "socks5" {
|
||||
// For SOCKS5 proxies, use the proxy package's FromURL
|
||||
return proxy.FromURL(proxyURL, proxy.Direct)
|
||||
}
|
||||
return nil, fmt.Errorf("unsupported proxy scheme: %s", proxyURL.Scheme)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user