本文整理汇总了Golang中net/http.Transport.ResponseHeaderTimeout方法的典型用法代码示例。如果您正苦于以下问题:Golang Transport.ResponseHeaderTimeout方法的具体用法?Golang Transport.ResponseHeaderTimeout怎么用?Golang Transport.ResponseHeaderTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/http.Transport
的用法示例。
在下文中一共展示了Transport.ResponseHeaderTimeout方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewSimplePool
// Creates a new HTTP connection pool using the given address and pool parameters.
//
// 'addr' is a net.Dial()-style 'host:port' destination for making the TCP connection for
// HTTP/HTTPS traffic. It will be used as the hostname by default for virtual hosting
// and SSL certificate validation; if you'd like to use a different hostname,
// set params.HostHeader.
func NewSimplePool(addr string, params ConnectionParams) *SimplePool {
pool := &SimplePool{
addr: addr,
params: params,
client: new(http.Client),
}
// setup HTTP transport
transport := new(http.Transport)
transport.ResponseHeaderTimeout = params.ResponseTimeout
transport.MaxIdleConnsPerHost = params.MaxIdle
transport.Proxy = http.ProxyFromEnvironment
if params.Dial == nil {
// dialTimeout could only be used in none proxy requests since it talks directly
// to pool.addr
if getenvEitherCase("HTTP_PROXY") == "" {
transport.Dial = pool.dialTimeout
}
} else {
transport.Dial = params.Dial
}
pool.transport = transport
pool.client.Transport = transport
if params.UseSSL && params.SkipVerifySSL {
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
return pool
}
示例2: New
// New creates a new Firebase reference
func New(url string) *Firebase {
var tr *http.Transport
tr = &http.Transport{
DisableKeepAlives: true, // https://code.google.com/p/go/issues/detail?id=3514
Dial: func(network, address string) (net.Conn, error) {
start := time.Now()
c, err := net.DialTimeout(network, address, TimeoutDuration)
tr.ResponseHeaderTimeout = TimeoutDuration - time.Since(start)
return c, err
},
}
var client *http.Client
client = &http.Client{
Transport: tr,
CheckRedirect: redirectPreserveHeaders,
}
return &Firebase{
url: sanitizeURL(url),
params: _url.Values{},
client: client,
stopWatching: make(chan struct{}),
}
}
示例3: NewSimplePool
// Creates a new HTTP connection pool using the given address and pool parameters.
//
// 'addr' is a net.Dial()-style 'host:port' destination for making the TCP connection for
// HTTP/HTTPS traffic. It will be used as the hostname by default for virtual hosting
// and SSL certificate validation; if you'd like to use a different hostname,
// set params.HostHeader.
func NewSimplePool(addr string, params ConnectionParams) *SimplePool {
pool := &SimplePool{
addr: addr,
params: params,
client: new(http.Client),
}
// It's desirable to enforce the timeout at the client-level since it
// includes the connection time, redirects and the time to finish reading
// the full response. Unlike ResponseHeaderTimeout supported by
// `http.Transport` which merely accounts for the timeout to receive the
// first response header byte. It ignores the time to send the request or
// the time to read the full response.
pool.client.Timeout = params.ResponseTimeout
// setup HTTP transport
transport := new(http.Transport)
transport.ResponseHeaderTimeout = params.ResponseTimeout
transport.MaxIdleConnsPerHost = params.MaxIdle
if params.Proxy != nil {
transport.Proxy = params.Proxy
} else {
transport.Proxy = http.ProxyFromEnvironment
}
if params.Dial == nil {
// dialTimeout could only be used in none proxy requests since it talks directly
// to pool.addr
if getenvEitherCase("HTTP_PROXY") == "" && params.Proxy == nil {
transport.Dial = pool.dialTimeout
}
} else {
transport.Dial = params.Dial
}
pool.transport = transport
pool.client.Transport = transport
if params.UseSSL && params.SkipVerifySSL {
transport.TLSClientConfig = &tls.Config{
InsecureSkipVerify: true,
}
}
return pool
}
示例4: New
// New creates a new Firebase reference. Using a custom client invalidates the
// TimeoutDuration guarantee.
func New(url string, client *http.Client) *Firebase {
if client == nil {
var tr *http.Transport
tr = &http.Transport{
Dial: func(network, address string) (net.Conn, error) {
start := time.Now()
c, err := net.DialTimeout(network, address, TimeoutDuration)
tr.ResponseHeaderTimeout = TimeoutDuration - time.Since(start)
return c, err
},
}
client = &http.Client{Transport: tr}
}
return &Firebase{
url: sanitizeURL(url),
params: _url.Values{},
client: client,
stopWatching: make(chan struct{}),
}
}
示例5: New
// New creates a new Firebase reference
func New(url string) *Firebase {
var tr *http.Transport
tr = &http.Transport{
DisableKeepAlives: true, // https://code.google.com/p/go/issues/detail?id=3514
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Dial: func(network, address string) (net.Conn, error) {
start := time.Now()
c, err := net.DialTimeout(network, address, TimeoutDuration)
tr.ResponseHeaderTimeout = TimeoutDuration - time.Since(start)
return c, err
},
}
return &Firebase{
url: sanitizeURL(url),
params: _url.Values{},
client: &http.Client{Transport: tr},
stopWatching: make(chan struct{}),
}
}
示例6: TestNewWithProvidedHttpClient
func TestNewWithProvidedHttpClient(t *testing.T) {
t.Parallel()
var tr *http.Transport
tr = &http.Transport{
DisableKeepAlives: true, // https://code.google.com/p/go/issues/detail?id=3514
Dial: func(network, address string) (net.Conn, error) {
start := time.Now()
c, err := net.DialTimeout(network, address, TimeoutDuration)
tr.ResponseHeaderTimeout = TimeoutDuration - time.Since(start)
return c, err
},
}
var client = http.Client{Transport: tr}
testCases := []struct {
givenURL string
}{
{
URL,
},
{
URL + "/",
},
{
"somefirebaseapp.firebaseIO.com",
},
{
"somefirebaseapp.firebaseIO.com/",
},
}
for _, tt := range testCases {
fb := New(tt.givenURL, &client)
assert.Equal(t, URL, fb.url, "givenURL: %s", tt.givenURL)
}
}
示例7: Transport
// Transport returns an http.RoundTripper with the correct timeouts
func (ci *ConfigInfo) Transport() http.RoundTripper {
noTransport.Do(func() {
// Start with a sensible set of defaults then override.
// This also means we get new stuff when it gets added to go
t := new(http.Transport)
setDefaults(t, http.DefaultTransport.(*http.Transport))
t.Proxy = http.ProxyFromEnvironment
t.MaxIdleConnsPerHost = 4 * (ci.Checkers + ci.Transfers + 1)
t.TLSHandshakeTimeout = ci.ConnectTimeout
t.ResponseHeaderTimeout = ci.Timeout
t.TLSClientConfig = &tls.Config{InsecureSkipVerify: ci.InsecureSkipVerify}
t.DisableCompression = *noGzip
// Set in http_old.go initTransport
// t.Dial
// Set in http_new.go initTransport
// t.DialContext
// t.IdelConnTimeout
// t.ExpectContinueTimeout
ci.initTransport(t)
// Wrap that http.Transport in our own transport
transport = NewTransport(t, ci.DumpHeaders, ci.DumpBodies)
})
return transport
}