FromURL returns a Dialer given a URL specification and an underlying Dialer for it to make network requests.
(u *url.URL, forward Dialer)
| 79 | // FromURL returns a Dialer given a URL specification and an underlying |
| 80 | // Dialer for it to make network requests. |
| 81 | func FromURL(u *url.URL, forward Dialer) (Dialer, error) { |
| 82 | var auth *Auth |
| 83 | if u.User != nil { |
| 84 | auth = new(Auth) |
| 85 | auth.User = u.User.Username() |
| 86 | if p, ok := u.User.Password(); ok { |
| 87 | auth.Password = p |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | switch u.Scheme { |
| 92 | case "socks5", "socks5h": |
| 93 | addr := u.Hostname() |
| 94 | port := u.Port() |
| 95 | if port == "" { |
| 96 | port = "1080" |
| 97 | } |
| 98 | return SOCKS5("tcp", net.JoinHostPort(addr, port), auth, forward) |
| 99 | } |
| 100 | |
| 101 | // If the scheme doesn't match any of the built-in schemes, see if it |
| 102 | // was registered by another package. |
| 103 | if proxySchemes != nil { |
| 104 | if f, ok := proxySchemes[u.Scheme]; ok { |
| 105 | return f(u, forward) |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return nil, errors.New("proxy: unknown scheme: " + u.Scheme) |
| 110 | } |
| 111 | |
| 112 | var ( |
| 113 | allProxyEnv = &envOnce{ |
searching dependent graphs…