mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 10:44:02 +03:00
Remove idle timeout from network
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
const (
|
||||
DefaultTimeout = 10 * time.Second
|
||||
DefaultIdleTimeout = time.Minute
|
||||
DefaultHTTPTimeout = 10 * time.Second
|
||||
DefaultBufferSize = 4096
|
||||
|
||||
|
||||
+1
-14
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user