mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 13:54:02 +03:00
Use HTTP timeout from config
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
const (
|
||||
DefaultTimeout = 10 * time.Second
|
||||
DefaultIdleTimeout = time.Minute
|
||||
DefaultHTTPTimeout = 10 * time.Second
|
||||
DefaultBufferSize = 4096
|
||||
|
||||
ProxyDialerOpenThreshold = 5
|
||||
@@ -18,9 +19,7 @@ const (
|
||||
ProxyDialerResetFailuresTimeout = 10 * time.Second
|
||||
|
||||
DefaultDOHHostname = "9.9.9.9"
|
||||
|
||||
DNSTimeout = 5 * time.Second
|
||||
HTTPTimeout = 10 * time.Second
|
||||
DNSTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -27,6 +27,7 @@ type network struct {
|
||||
dialer Dialer
|
||||
dns doh.Resolver
|
||||
idleTimeout time.Duration
|
||||
httpTimeout time.Duration
|
||||
userAgent string
|
||||
}
|
||||
|
||||
@@ -123,10 +124,12 @@ func (n *network) MakeHTTPClient(dialFunc DialFunc) *http.Client {
|
||||
dialFunc = n.DialContext
|
||||
}
|
||||
|
||||
return makeHTTPClient(n.userAgent, HTTPTimeout, dialFunc)
|
||||
return makeHTTPClient(n.userAgent, n.httpTimeout, dialFunc)
|
||||
}
|
||||
|
||||
func NewNetwork(dialer Dialer, userAgent, dohHostname string, idleTimeout time.Duration) (Network, error) {
|
||||
func NewNetwork(dialer Dialer,
|
||||
userAgent, dohHostname string,
|
||||
httpTimeout, idleTimeout time.Duration) (Network, error) {
|
||||
switch {
|
||||
case idleTimeout < 0:
|
||||
return nil, fmt.Errorf("timeout should be positive number %s", idleTimeout)
|
||||
@@ -141,6 +144,7 @@ func NewNetwork(dialer Dialer, userAgent, dohHostname string, idleTimeout time.D
|
||||
return &network{
|
||||
dialer: dialer,
|
||||
idleTimeout: idleTimeout,
|
||||
httpTimeout: httpTimeout,
|
||||
userAgent: userAgent,
|
||||
dns: doh.Resolver{
|
||||
Host: dohHostname,
|
||||
|
||||
Reference in New Issue
Block a user