Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problems introduced by #58 #61

Merged
merged 1 commit into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 8 additions & 31 deletions sockets/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package sockets

import (
"net"
"net/url"
"os"
"strings"

"golang.org/x/net/proxy"
)

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

// DialerFromEnvironment takes in a "direct" *net.Dialer and returns a
// proxy.Dialer which will route the connections through the proxy using the
// given dialer.
func DialerFromEnvironment(direct *net.Dialer) (proxy.Dialer, error) {
PaulSD marked this conversation as resolved.
Show resolved Hide resolved
allProxy := GetProxyEnv("all_proxy")
if len(allProxy) == 0 {
return direct, nil
}

proxyURL, err := url.Parse(allProxy)
if err != nil {
return direct, err
}

proxyFromURL, err := proxy.FromURL(proxyURL, direct)
if err != nil {
return direct, err
}

noProxy := GetProxyEnv("no_proxy")
if len(noProxy) == 0 {
return proxyFromURL, nil
}

perHost := proxy.NewPerHost(proxyFromURL, direct)
perHost.AddFromString(noProxy)

return perHost, nil
// DialerFromEnvironment was previously used to configure a net.Dialer to route
// connections through a SOCKS proxy.
// DEPRECATED: SOCKS proxies are now supported by configuring only
// http.Transport.Proxy, and no longer require changing http.Transport.Dial.
// Therefore, only sockets.ConfigureTransport() needs to be called, and any
// sockets.DialerFromEnvironment() calls can be dropped.
func DialerFromEnvironment(direct *net.Dialer) (*net.Dialer, error) {
return direct, nil
}
8 changes: 0 additions & 8 deletions sockets/sockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sockets

import (
"errors"
"net"
"net/http"
"time"
)
Expand All @@ -26,13 +25,6 @@ func ConfigureTransport(tr *http.Transport, proto, addr string) error {
return configureNpipeTransport(tr, proto, addr)
default:
tr.Proxy = http.ProxyFromEnvironment
dialer, err := DialerFromEnvironment(&net.Dialer{
Timeout: defaultTimeout,
})
if err != nil {
return err
}
tr.DialContext = dialer.DialContext
Copy link

@jamesmoessis jamesmoessis Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have caused a problem for me because now the unix transport is used when I have specified an HTTP endpoint.

The dial context is used and for an http endpoint it tries to connect to a unix socket instead of a tcp socket.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following you ...

The code you highlighted here was only used to configure the proxy on Go <1.9, and was removed because it is redundant and no longer necessary in Go >=1.9.

Removal of this code should not impact transport selection. Transport selection occurs a few lines earlier, and was not modified by this change: https://github.com/docker/go-connections/blob/master/sockets/sockets.go#L17

Maybe you have a proxy configured using a UNIX socket?

}
return nil
}
1 change: 1 addition & 0 deletions sockets/sockets_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package sockets

import (
"context"
"fmt"
"net"
"net/http"
Expand Down
4 changes: 1 addition & 3 deletions sockets/sockets_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sockets

import (
"context"
"net"
"net/http"
"time"
Expand All @@ -15,9 +16,6 @@ func configureUnixTransport(tr *http.Transport, proto, addr string) error {
func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
// No need for compression in local communications.
tr.DisableCompression = true
dialer := &net.Dialer{
Timeout: defaultTimeout,
}
tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
// DialPipeContext() has been added to winio:
// https://github.com/Microsoft/go-winio/commit/5fdbdcc2ae1c7e1073157fa7cb34a15eab472e1d
Expand Down