-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransport.go
More file actions
45 lines (40 loc) · 1.35 KB
/
Copy pathtransport.go
File metadata and controls
45 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package hacktheconn
import (
"net/http"
"net/url"
)
// DefaultTransportFactory creates a transport based on the provided proxy URL.
// It supports "http", "https", "direct", and SOCKS5 protocols.
// If the scheme is "http" or "https", it uses ProxyHTTPTransport.
// If the scheme is "direct", it uses DirectTransport.
// For any other scheme, it defaults to ProxySocks5Transport.
// This is useful for dynamically selecting transports based on the proxy URL.
// It returns an error if the proxy URL is invalid.
func DefaultTransportFactory(proxyURL string) (*http.Transport, error) {
u, err := url.Parse(proxyURL)
if err != nil {
return nil, err
}
switch u.Scheme {
case "http", "https":
return ProxyHTTPTransport(proxyURL)
case "direct":
return DirectTransport()
default:
return ProxySocks5Transport(proxyURL)
}
}
// DirectTransportFactory creates multiple direct transports (no proxy).
// This is useful when you're behind a load balancer and want multiple connections
// to take advantage of upstream rebalancing.
func DirectTransportFactory(_ string) (*http.Transport, error) {
return DirectTransport()
}
// MultiDirectTransportFactory creates a slice of direct transports for strategies.
func MultiDirectTransportFactory(count int) []string {
transports := make([]string, count)
for i := range count {
transports[i] = "direct://"
}
return transports
}