2013-11-22 09:52:19 +04:00
|
|
|
// Copyright 2013 The Go Authors. All rights reserved.
|
2013-07-05 00:00:10 +04:00
|
|
|
//
|
2013-11-22 09:52:19 +04:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd.
|
2013-07-05 00:00:10 +04:00
|
|
|
|
|
|
|
// This file implements an http.Client with request timeouts set by command
|
2013-11-22 09:52:19 +04:00
|
|
|
// line flags.
|
2013-07-05 00:00:10 +04:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2015-03-02 18:26:43 +03:00
|
|
|
|
|
|
|
"github.com/golang/gddo/httputil"
|
2013-07-05 00:00:10 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
dialTimeout = flag.Duration("dial_timeout", 5*time.Second, "Timeout for dialing an HTTP connection.")
|
|
|
|
requestTimeout = flag.Duration("request_timeout", 20*time.Second, "Time out for roundtripping an HTTP request.")
|
|
|
|
)
|
|
|
|
|
2015-03-02 18:26:43 +03:00
|
|
|
func newHTTPClient() *http.Client {
|
|
|
|
return &http.Client{
|
|
|
|
Transport: httputil.NewAuthTransport(
|
|
|
|
&http.Transport{
|
|
|
|
Proxy: http.ProxyFromEnvironment,
|
|
|
|
Dial: (&net.Dialer{
|
|
|
|
Timeout: *dialTimeout,
|
|
|
|
KeepAlive: *requestTimeout / 2,
|
|
|
|
}).Dial,
|
|
|
|
ResponseHeaderTimeout: *requestTimeout / 2,
|
|
|
|
TLSHandshakeTimeout: *requestTimeout / 2,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Timeout: *requestTimeout,
|
2014-01-08 21:01:09 +04:00
|
|
|
}
|
2013-07-05 00:00:10 +04:00
|
|
|
}
|