]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Provide trackers specific http client
authordz0ny <dz0ny@ubuntu.si>
Sat, 28 Oct 2017 14:29:36 +0000 (16:29 +0200)
committerdz0ny <dz0ny@ubuntu.si>
Sat, 28 Oct 2017 14:30:10 +0000 (16:30 +0200)
Mainly follows https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779
but also disables HTTPS certificate verification.

tracker/http.go

index d295fc55d9faebdfc37839cc32c18ddc19e55eae..cdab2f1b980b21d8706ab83fc8d531c7021b7f50 100644 (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
        }