43 lines
856 B
Go
43 lines
856 B
Go
|
package falcon
|
||
|
|
||
|
import (
|
||
|
"crypto/tls"
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
"net/url"
|
||
|
|
||
|
"h12.io/socks"
|
||
|
)
|
||
|
|
||
|
// Transport will return a http.Transport for the proxy protocol
|
||
|
func Transport(proxy string) (scheme string, transport *http.Transport, err error) {
|
||
|
// Parse URL
|
||
|
proxyURL, err := url.Parse(proxy)
|
||
|
if err != nil {
|
||
|
return "", nil, err
|
||
|
}
|
||
|
|
||
|
// Check scheme & create transport
|
||
|
switch proxyURL.Scheme {
|
||
|
case "socks5", "socks4", "socks4a":
|
||
|
transport = &http.Transport{
|
||
|
Dial: socks.Dial(proxy),
|
||
|
}
|
||
|
case "https", "http":
|
||
|
transport = &http.Transport{
|
||
|
Proxy: http.ProxyURL(proxyURL),
|
||
|
}
|
||
|
default:
|
||
|
return "", nil, fmt.Errorf(
|
||
|
"unknown proxy protocol scheme: %s",
|
||
|
proxyURL.Scheme,
|
||
|
)
|
||
|
}
|
||
|
|
||
|
// Set options
|
||
|
transport.DisableKeepAlives = true
|
||
|
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||
|
|
||
|
return proxyURL.Scheme, transport, nil
|
||
|
}
|