Remove idle timeout from network

This commit is contained in:
9seconds
2021-03-17 22:08:47 +03:00
parent adf4ab1a35
commit f21ee40baf
7 changed files with 11 additions and 31 deletions
-1
View File
@@ -9,7 +9,6 @@ import (
const (
DefaultTimeout = 10 * time.Second
DefaultIdleTimeout = time.Minute
DefaultHTTPTimeout = 10 * time.Second
DefaultBufferSize = 4096
+1 -14
View File
@@ -27,7 +27,6 @@ func (n networkHTTPTransport) RoundTrip(req *http.Request) (*http.Response, erro
type network struct {
dialer Dialer
dns doh.Resolver
idleTimeout time.Duration
httpTimeout time.Duration
userAgent string
}
@@ -71,10 +70,6 @@ func (n *network) MakeHTTPClient(dialFunc func(ctx context.Context,
return makeHTTPClient(n.userAgent, n.httpTimeout, dialFunc)
}
func (n *network) IdleTimeout() time.Duration {
return n.idleTimeout
}
func (n *network) dnsResolve(protocol, address string) ([]string, error) {
if net.ParseIP(address) != nil {
return []string{address}, nil
@@ -131,7 +126,7 @@ func (n *network) dnsResolve(protocol, address string) ([]string, error) {
func NewNetwork(dialer Dialer,
userAgent, dohHostname string,
httpTimeout, idleTimeout time.Duration) (mtglib.Network, error) {
httpTimeout time.Duration) (mtglib.Network, error) {
switch {
case httpTimeout < 0:
return nil, fmt.Errorf("timeout should be positive number %s", httpTimeout)
@@ -139,20 +134,12 @@ func NewNetwork(dialer Dialer,
httpTimeout = DefaultHTTPTimeout
}
switch {
case idleTimeout < 0:
return nil, fmt.Errorf("timeout should be positive number %s", idleTimeout)
case idleTimeout == 0:
idleTimeout = DefaultIdleTimeout
}
if net.ParseIP(dohHostname) == nil {
return nil, fmt.Errorf("hostname %s should be IP address", dohHostname)
}
return &network{
dialer: dialer,
idleTimeout: idleTimeout,
httpTimeout: httpTimeout,
userAgent: userAgent,
dns: doh.Resolver{