Add PatchHTTPClient method

This method is mostly required for testing
This commit is contained in:
9seconds
2021-03-11 05:01:26 +03:00
parent 24add0dce4
commit 757ea5b63c
3 changed files with 6 additions and 0 deletions
+2
View File
@@ -80,6 +80,8 @@ func (c *cliCommandAccess) getIP(protocol string) net.IP {
}, },
} }
c.network.PatchHTTPClient(client)
resp, err := client.Get("https://ifconfig.co") // nolint: bodyclose, noctx resp, err := client.Get("https://ifconfig.co") // nolint: bodyclose, noctx
if err != nil { if err != nil {
return nil return nil
+1
View File
@@ -39,4 +39,5 @@ type Network interface {
DNSResolve(network, hostname string) (ips []string, err error) DNSResolve(network, hostname string) (ips []string, err error)
MakeHTTPClient(timeout time.Duration) *http.Client MakeHTTPClient(timeout time.Duration) *http.Client
IdleTimeout() time.Duration IdleTimeout() time.Duration
PatchHTTPClient(*http.Client)
} }
+3
View File
@@ -120,6 +120,9 @@ func (n *network) MakeHTTPClient(timeout time.Duration) *http.Client {
} }
} }
func (n *network) PatchHTTPClient(_ *http.Client) {
}
func NewNetwork(dialer Dialer, dohHostname string, idleTimeout time.Duration) (Network, error) { func NewNetwork(dialer Dialer, dohHostname string, idleTimeout time.Duration) (Network, error) {
switch { switch {
case idleTimeout < 0: case idleTimeout < 0: