MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / OptimisticHTTPProxyDialerFromURL

Function OptimisticHTTPProxyDialerFromURL

dialer/optimistic.go:36–75  ·  view source on GitHub ↗
(u *url.URL, next xproxy.Dialer)

Source from the content-addressed store, hash-verified

34}
35
36func 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
77func (d *OptimisticHTTPProxyDialer) Dial(network, address string) (net.Conn, error) {
78 return d.DialContext(context.Background(), network, address)

Callers

nothing calls this directly

Calls 4

TLSConfigFromURLFunction · 0.92
TLSFactoryFromURLFunction · 0.92
ErrorfMethod · 0.80

Tested by

no test coverage detected