(u *url.URL, next xproxy.Dialer)
| 34 | } |
| 35 | |
| 36 | func OptimisticHTTPProxyDialerFromURL(u *url.URL, next xproxy.Dialer) (xproxy.Dialer, error) { |
| 37 | host := u.Hostname() |
| 38 | port := u.Port() |
| 39 | |
| 40 | var ( |
| 41 | tlsConfig *tls.Config |
| 42 | tlsFactory func(net.Conn, *tls.Config) net.Conn |
| 43 | err error |
| 44 | ) |
| 45 | switch strings.ToLower(u.Scheme) { |
| 46 | case "http+optimistic": |
| 47 | if port == "" { |
| 48 | port = "80" |
| 49 | } |
| 50 | case "https+optimistic": |
| 51 | if port == "" { |
| 52 | port = "443" |
| 53 | } |
| 54 | tlsConfig, err = tlsutil.TLSConfigFromURL(u) |
| 55 | if err != nil { |
| 56 | return nil, fmt.Errorf("TLS configuration failed: %w", err) |
| 57 | } |
| 58 | tlsFactory, err = tlsutil.TLSFactoryFromURL(u) |
| 59 | if err != nil { |
| 60 | return nil, fmt.Errorf("TLS configuration failed: %w", err) |
| 61 | } |
| 62 | default: |
| 63 | return nil, errors.New("unsupported proxy type") |
| 64 | } |
| 65 | |
| 66 | address := net.JoinHostPort(host, port) |
| 67 | |
| 68 | return &OptimisticHTTPProxyDialer{ |
| 69 | address: address, |
| 70 | tlsConfig: tlsConfig, |
| 71 | tlsFactory: tlsFactory, |
| 72 | userinfo: u.User, |
| 73 | next: MaybeWrapWithContextDialer(next), |
| 74 | }, nil |
| 75 | } |
| 76 | |
| 77 | func (d *OptimisticHTTPProxyDialer) Dial(network, address string) (net.Conn, error) { |
| 78 | return d.DialContext(context.Background(), network, address) |
nothing calls this directly
no test coverage detected