reverting usage of proxy for http requests
This commit is contained in:
parent
02f37a34ee
commit
9dc89ab6dc
@ -10,6 +10,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -220,6 +222,12 @@ func NewClient(cfg *ClientConfig) (cl *Client, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if cl.config.HTTPProxy == nil && cl.config.ProxyURL != "" {
|
||||
if fixedURL, err := url.Parse(cl.config.ProxyURL); err == nil {
|
||||
cl.config.HTTPProxy = http.ProxyURL(fixedURL)
|
||||
}
|
||||
}
|
||||
|
||||
cl.conns, err = listenAll(cl.enabledPeerNetworks(), cl.config.ListenHost, cl.config.ListenPort, cl.config.ProxyURL, cl.firewallCallback)
|
||||
if err != nil {
|
||||
return
|
||||
|
11
config.go
11
config.go
@ -2,6 +2,8 @@ package torrent
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/anacrolix/dht"
|
||||
@ -67,7 +69,8 @@ type ClientConfig struct {
|
||||
EncryptionPolicy
|
||||
|
||||
// Sets usage of Socks5 Proxy. Authentication should be included in the url if needed.
|
||||
// Example of setting: "socks5://demo:demo@192.168.99.100:1080"
|
||||
// Examples: socks5://demo:demo@192.168.99.100:1080
|
||||
// http://proxy.domain.com:3128
|
||||
ProxyURL string
|
||||
|
||||
IPBlocklist iplist.Ranger
|
||||
@ -77,6 +80,12 @@ type ClientConfig struct {
|
||||
// Perform logging and any other behaviour that will help debug.
|
||||
Debug bool `help:"enable debugging"`
|
||||
|
||||
// HTTPProxy defines proxy for HTTP requests.
|
||||
// Format: func(*Request) (*url.URL, error),
|
||||
// or result of http.ProxyURL(HTTPProxy).
|
||||
// By default, it is composed from ClientConfig.ProxyURL,
|
||||
// if not set explicitly in ClientConfig struct
|
||||
HTTPProxy func(*http.Request) (*url.URL, error)
|
||||
// HTTPUserAgent changes default UserAgent for HTTP requests
|
||||
HTTPUserAgent string
|
||||
// Updated occasionally to when there's been some changes to client
|
||||
|
@ -105,6 +105,7 @@ func announceHTTP(opt Announce, _url *url.URL) (ret AnnounceResponse, err error)
|
||||
Dial: (&net.Dialer{
|
||||
Timeout: 15 * time.Second,
|
||||
}).Dial,
|
||||
Proxy: opt.HTTPProxy,
|
||||
TLSHandshakeTimeout: 15 * time.Second,
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
|
@ -2,6 +2,7 @@ package tracker
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/anacrolix/dht/krpc"
|
||||
@ -52,6 +53,7 @@ type Announce struct {
|
||||
TrackerUrl string
|
||||
Request AnnounceRequest
|
||||
HostHeader string
|
||||
HTTPProxy func(*http.Request) (*url.URL, error)
|
||||
ServerName string
|
||||
UserAgent string
|
||||
UdpNetwork string
|
||||
|
@ -111,6 +111,7 @@ func (me *trackerScraper) announce() (ret trackerAnnounceResult) {
|
||||
req := me.t.announceRequest()
|
||||
me.t.cl.unlock()
|
||||
res, err := tracker.Announce{
|
||||
HTTPProxy: me.t.cl.config.HTTPProxy,
|
||||
UserAgent: me.t.cl.config.HTTPUserAgent,
|
||||
TrackerUrl: me.trackerUrl(ip),
|
||||
Request: req,
|
||||
|
Loading…
x
Reference in New Issue
Block a user