Skip to content

Commit fb772cf

Browse files
committed
Fix problems introduced by 61039d0
* Add missing import of "context" (Fixes #60) * Drop configuration of the http.Transport.DialContext based on proxy settings (This was originally needed for SOCKS support, but has not been required since https://go-review.googlesource.com/c/go/+/35488/ in Go 1.9, and is no longer supported as of https://go-review.googlesource.com/c/go/+/41031/ in Go 1.11) Signed-off-by: Paul Donohue <[email protected]>
1 parent ccfcbc5 commit fb772cf

4 files changed

Lines changed: 10 additions & 42 deletions

File tree

sockets/proxy.go

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ package sockets
22

33
import (
44
"net"
5-
"net/url"
65
"os"
76
"strings"
8-
9-
"golang.org/x/net/proxy"
107
)
118

129
// GetProxyEnv allows access to the uppercase and the lowercase forms of
@@ -20,32 +17,12 @@ func GetProxyEnv(key string) string {
2017
return proxyValue
2118
}
2219

23-
// DialerFromEnvironment takes in a "direct" *net.Dialer and returns a
24-
// proxy.Dialer which will route the connections through the proxy using the
25-
// given dialer.
26-
func DialerFromEnvironment(direct *net.Dialer) (proxy.Dialer, error) {
27-
allProxy := GetProxyEnv("all_proxy")
28-
if len(allProxy) == 0 {
29-
return direct, nil
30-
}
31-
32-
proxyURL, err := url.Parse(allProxy)
33-
if err != nil {
34-
return direct, err
35-
}
36-
37-
proxyFromURL, err := proxy.FromURL(proxyURL, direct)
38-
if err != nil {
39-
return direct, err
40-
}
41-
42-
noProxy := GetProxyEnv("no_proxy")
43-
if len(noProxy) == 0 {
44-
return proxyFromURL, nil
45-
}
46-
47-
perHost := proxy.NewPerHost(proxyFromURL, direct)
48-
perHost.AddFromString(noProxy)
49-
50-
return perHost, nil
20+
// DialerFromEnvironment was previously used to configure a net.Dialer to route
21+
// connections through a SOCKS proxy.
22+
// DEPRECATED: SOCKS proxies are now supported by configuring only
23+
// http.Transport.Proxy, and no longer require changing http.Transport.Dial.
24+
// Therefore, only sockets.ConfigureTransport() needs to be called, and any
25+
// sockets.DialerFromEnvironment() calls can be dropped.
26+
func DialerFromEnvironment(direct *net.Dialer) (*net.Dialer, error) {
27+
return direct, nil
5128
}

sockets/sockets.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package sockets
33

44
import (
55
"errors"
6-
"net"
76
"net/http"
87
"time"
98
)
@@ -26,13 +25,6 @@ func ConfigureTransport(tr *http.Transport, proto, addr string) error {
2625
return configureNpipeTransport(tr, proto, addr)
2726
default:
2827
tr.Proxy = http.ProxyFromEnvironment
29-
dialer, err := DialerFromEnvironment(&net.Dialer{
30-
Timeout: defaultTimeout,
31-
})
32-
if err != nil {
33-
return err
34-
}
35-
tr.DialContext = dialer.DialContext
3628
}
3729
return nil
3830
}

sockets/sockets_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package sockets
44

55
import (
6+
"context"
67
"fmt"
78
"net"
89
"net/http"

sockets/sockets_windows.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sockets
22

33
import (
4+
"context"
45
"net"
56
"net/http"
67
"time"
@@ -15,9 +16,6 @@ func configureUnixTransport(tr *http.Transport, proto, addr string) error {
1516
func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
1617
// No need for compression in local communications.
1718
tr.DisableCompression = true
18-
dialer := &net.Dialer{
19-
Timeout: defaultTimeout,
20-
}
2119
tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
2220
// DialPipeContext() has been added to winio:
2321
// https://github.com/Microsoft/go-winio/commit/5fdbdcc2ae1c7e1073157fa7cb34a15eab472e1d

0 commit comments

Comments
 (0)