2
0
mirror of synced 2025-02-23 14:18:13 +00:00

Provide trackers specific http client

Mainly follows https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
but also disables HTTPS certificate verification.
This commit is contained in:
dz0ny 2017-10-28 16:29:36 +02:00
parent 911423307d
commit caa58d0f69

View File

@ -24,6 +24,17 @@ type httpResponse struct {
Peers interface{} `bencode:"peers"`
}
var netClient = &http.Client{
Timeout: time.Second * 15,
Transport: &http.Transport{
Dial: (&net.Dialer{
Timeout: 15 * time.Second,
}).Dial,
TLSHandshakeTimeout: 15 * time.Second,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
func (r *httpResponse) UnmarshalPeers() (ret []Peer, err error) {
switch v := r.Peers.(type) {
case string:
@ -78,7 +89,7 @@ func announceHTTP(ar *AnnounceRequest, _url *url.URL, host string) (ret Announce
setAnnounceParams(_url, ar)
req, err := http.NewRequest("GET", _url.String(), nil)
req.Host = host
resp, err := http.DefaultClient.Do(req)
resp, err := netClient.Do(req)
if err != nil {
return
}