]> Sergey Matveev's repositories - btrtrc.git/blob - tracker/http/client.go
Add http tracker AllowKeepAlive
[btrtrc.git] / tracker / http / client.go
1 package http
2
3 import (
4         "crypto/tls"
5         "net/http"
6         "net/url"
7 )
8
9 type Client struct {
10         hc   *http.Client
11         url_ *url.URL
12 }
13
14 type ProxyFunc func(*http.Request) (*url.URL, error)
15
16 type NewClientOpts struct {
17         Proxy          ProxyFunc
18         ServerName     string
19         AllowKeepAlive bool
20 }
21
22 func NewClient(url_ *url.URL, opts NewClientOpts) Client {
23         return Client{
24                 url_: url_,
25                 hc: &http.Client{
26                         Transport: &http.Transport{
27                                 Proxy: opts.Proxy,
28                                 TLSClientConfig: &tls.Config{
29                                         InsecureSkipVerify: true,
30                                         ServerName:         opts.ServerName,
31                                 },
32                                 // This is for S3 trackers that hold connections open.
33                                 DisableKeepAlives: !opts.AllowKeepAlive,
34                         },
35                 },
36         }
37 }
38
39 func (cl Client) Close() error {
40         cl.hc.CloseIdleConnections()
41         return nil
42 }