コード例 #1
0
ファイル: stats.go プロジェクト: z0rr0/luss
// Callback is a callback handler.
// It does HTTP request if it's needed.
func Callback(ctx context.Context, cu *trim.CustomURL) error {
	req, err := cu.Callback()
	if err != nil {
		// empty callback
		if err == trim.ErrEmptyCallback {
			return nil
		}
		return err
	}
	req.Header = http.Header{"User-Agent": {httpUserAgent}}
	timeoutTLS, timeout := 5*time.Second, 7*time.Second
	tr := &http.Transport{
		Proxy:               http.ProxyFromEnvironment,
		Dial:                (&net.Dialer{Timeout: timeout}).Dial,
		TLSHandshakeTimeout: timeoutTLS,
		// TLSClientConfig:     &tls.Config{InsecureSkipVerify: false},
	}
	client := &http.Client{Transport: tr, Timeout: timeout}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	_, err = ioutil.ReadAll(resp.Body)
	return err
}