customize tcp handshake timeouts
shot in the dark at avoiding tcp read timeouts by extending the tcp dialer and tls handshake timeouts in the graph client transport.
This commit is contained in:
parent
a9918d2f78
commit
64a122413b
@ -37,7 +37,7 @@ func NewHTTPWrapper(opts ...Option) *httpWrapper {
|
||||
rt = customTransport{
|
||||
n: pipeline{
|
||||
middlewares: internalMiddleware(cc),
|
||||
transport: defaultTransport(),
|
||||
transport: defaultHttpTransport(),
|
||||
},
|
||||
}
|
||||
redirect = func(req *http.Request, via []*http.Request) error {
|
||||
@ -132,13 +132,6 @@ func (pl pipeline) Next(req *http.Request, idx int) (*http.Response, error) {
|
||||
return pl.transport.RoundTrip(req)
|
||||
}
|
||||
|
||||
func defaultTransport() http.RoundTripper {
|
||||
defaultTransport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
defaultTransport.ForceAttemptHTTP2 = true
|
||||
|
||||
return defaultTransport
|
||||
}
|
||||
|
||||
func internalMiddleware(cc *clientConfig) []khttp.Middleware {
|
||||
mw := []khttp.Middleware{
|
||||
&RetryMiddleware{
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package graph
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@ -150,12 +151,14 @@ func GetAuth(tenant string, client string, secret string) (*kauth.AzureIdentityA
|
||||
// can utilize it on a per-download basis.
|
||||
func KiotaHTTPClient(opts ...Option) *http.Client {
|
||||
var (
|
||||
clientOptions = msgraphsdkgo.GetDefaultClientOptions()
|
||||
cc = populateConfig(opts...)
|
||||
middlewares = kiotaMiddlewares(&clientOptions, cc)
|
||||
httpClient = msgraphgocore.GetDefaultClient(&clientOptions, middlewares...)
|
||||
clientOptions = msgraphsdkgo.GetDefaultClientOptions()
|
||||
cc = populateConfig(opts...)
|
||||
middlewares = kiotaMiddlewares(&clientOptions, cc)
|
||||
httpClient = msgraphgocore.GetDefaultClient(&clientOptions, middlewares...)
|
||||
customTransport = khttp.NewCustomTransportWithParentTransport(defaultHttpTransport(), middlewares...)
|
||||
)
|
||||
|
||||
httpClient.Transport = customTransport
|
||||
httpClient.Timeout = defaultHTTPClientTimeout
|
||||
|
||||
cc.apply(httpClient)
|
||||
@ -163,6 +166,22 @@ func KiotaHTTPClient(opts ...Option) *http.Client {
|
||||
return httpClient
|
||||
}
|
||||
|
||||
func defaultHttpTransport() *http.Transport {
|
||||
defaultTransport := khttp.GetDefaultTransport().(*http.Transport).Clone()
|
||||
|
||||
// default: 10 seconds
|
||||
defaultTransport.TLSHandshakeTimeout = 30 * time.Second
|
||||
|
||||
// default: 30 seconds
|
||||
nd := &net.Dialer{
|
||||
Timeout: 60 * time.Second,
|
||||
KeepAlive: 60 * time.Second,
|
||||
}
|
||||
defaultTransport.DialContext = nd.DialContext
|
||||
|
||||
return defaultTransport
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// HTTP Client Config
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user