add context dialer support #88
							
								
								
									
										26
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								http.go
									
									
									
									
									
								
							@@ -692,11 +692,21 @@ func NewClient(opts ...client.Option) client.Client {
 | 
				
			|||||||
		opts: options,
 | 
							opts: options,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dialer, ok := options.Context.Value(httpDialerKey{}).(*net.Dialer)
 | 
						var dialer func(context.Context, string) (net.Conn, error)
 | 
				
			||||||
	if !ok {
 | 
						if v, ok := options.Context.Value(httpDialerKey{}).(*net.Dialer); ok {
 | 
				
			||||||
		dialer = &net.Dialer{
 | 
							dialer = func(ctx context.Context, addr string) (net.Conn, error) {
 | 
				
			||||||
			Timeout:   30 * time.Second,
 | 
								return v.DialContext(ctx, "tcp", addr)
 | 
				
			||||||
			KeepAlive: 30 * time.Second,
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if options.ContextDialer != nil {
 | 
				
			||||||
 | 
							dialer = options.ContextDialer
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if dialer == nil {
 | 
				
			||||||
 | 
							dialer = func(ctx context.Context, addr string) (net.Conn, error) {
 | 
				
			||||||
 | 
								return (&net.Dialer{
 | 
				
			||||||
 | 
									Timeout:   30 * time.Second,
 | 
				
			||||||
 | 
									KeepAlive: 30 * time.Second,
 | 
				
			||||||
 | 
								}).DialContext(ctx, "tcp", addr)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -705,8 +715,10 @@ func NewClient(opts ...client.Option) client.Client {
 | 
				
			|||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		// TODO customTransport := http.DefaultTransport.(*http.Transport).Clone()
 | 
							// TODO customTransport := http.DefaultTransport.(*http.Transport).Clone()
 | 
				
			||||||
		tr := &http.Transport{
 | 
							tr := &http.Transport{
 | 
				
			||||||
			Proxy:                 http.ProxyFromEnvironment,
 | 
								Proxy: http.ProxyFromEnvironment,
 | 
				
			||||||
			DialContext:           dialer.DialContext,
 | 
								DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
 | 
				
			||||||
 | 
									return dialer(ctx, addr)
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
			ForceAttemptHTTP2:     true,
 | 
								ForceAttemptHTTP2:     true,
 | 
				
			||||||
			MaxConnsPerHost:       100,
 | 
								MaxConnsPerHost:       100,
 | 
				
			||||||
			MaxIdleConns:          20,
 | 
								MaxIdleConns:          20,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user