2022-12-05 06:50:39 +00:00
|
|
|
package httpTracker
|
2021-06-24 00:39:56 +00:00
|
|
|
|
|
|
|
import (
|
2022-07-07 05:51:58 +00:00
|
|
|
"context"
|
2021-06-24 00:39:56 +00:00
|
|
|
"crypto/tls"
|
2022-07-07 05:51:58 +00:00
|
|
|
"net"
|
2021-06-24 00:39:56 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Client struct {
|
|
|
|
hc *http.Client
|
|
|
|
url_ *url.URL
|
|
|
|
}
|
|
|
|
|
2023-02-18 07:35:22 +00:00
|
|
|
type (
|
|
|
|
ProxyFunc func(*http.Request) (*url.URL, error)
|
|
|
|
DialContextFunc func(ctx context.Context, network, addr string) (net.Conn, error)
|
|
|
|
)
|
2021-06-24 00:39:56 +00:00
|
|
|
|
|
|
|
type NewClientOpts struct {
|
2021-06-25 05:00:09 +00:00
|
|
|
Proxy ProxyFunc
|
2022-07-07 05:51:58 +00:00
|
|
|
DialContext DialContextFunc
|
2021-06-25 05:00:09 +00:00
|
|
|
ServerName string
|
|
|
|
AllowKeepAlive bool
|
2021-06-24 00:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewClient(url_ *url.URL, opts NewClientOpts) Client {
|
|
|
|
return Client{
|
|
|
|
url_: url_,
|
|
|
|
hc: &http.Client{
|
|
|
|
Transport: &http.Transport{
|
2022-07-07 05:51:58 +00:00
|
|
|
DialContext: opts.DialContext,
|
2022-11-15 12:22:10 +00:00
|
|
|
Proxy: opts.Proxy,
|
2021-06-24 00:39:56 +00:00
|
|
|
TLSClientConfig: &tls.Config{
|
|
|
|
InsecureSkipVerify: true,
|
|
|
|
ServerName: opts.ServerName,
|
|
|
|
},
|
|
|
|
// This is for S3 trackers that hold connections open.
|
2021-06-25 05:00:09 +00:00
|
|
|
DisableKeepAlives: !opts.AllowKeepAlive,
|
2021-06-24 00:39:56 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cl Client) Close() error {
|
|
|
|
cl.hc.CloseIdleConnections()
|
|
|
|
return nil
|
|
|
|
}
|