2022-05-23 01:20:40 +00:00
|
|
|
package prox5
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetHTTPClient retrieves a pointer to an http.Client powered by MysteryDialer.
|
2022-06-26 02:51:42 +00:00
|
|
|
func (pe *ProxyEngine) GetHTTPClient() *http.Client {
|
2022-05-23 01:20:40 +00:00
|
|
|
var htp func(*http.Request) (*url.URL, error)
|
|
|
|
var dctx func(ctx context.Context, network string, addr string) (net.Conn, error)
|
2022-06-26 02:51:42 +00:00
|
|
|
if httun, htok := pe.GetHTTPTunnel(); htok {
|
2022-05-23 01:20:40 +00:00
|
|
|
httprox, uerr := url.Parse("http://" + httun.Endpoint)
|
|
|
|
if uerr == nil {
|
|
|
|
htp = http.ProxyURL(httprox)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if htp == nil {
|
2022-06-26 02:51:42 +00:00
|
|
|
dctx = pe.DialContext
|
2022-05-23 01:20:40 +00:00
|
|
|
}
|
|
|
|
return &http.Client{
|
|
|
|
Transport: &http.Transport{
|
|
|
|
Proxy: htp,
|
|
|
|
DialContext: dctx,
|
|
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
2022-06-26 02:51:42 +00:00
|
|
|
TLSHandshakeTimeout: pe.GetServerTimeout(),
|
2022-05-23 01:20:40 +00:00
|
|
|
DisableKeepAlives: true,
|
|
|
|
DisableCompression: false,
|
|
|
|
MaxIdleConnsPerHost: 5,
|
2022-06-26 02:51:42 +00:00
|
|
|
IdleConnTimeout: pe.GetServerTimeout(),
|
|
|
|
ResponseHeaderTimeout: pe.GetServerTimeout(),
|
2022-05-23 01:20:40 +00:00
|
|
|
},
|
2022-06-26 02:51:42 +00:00
|
|
|
Timeout: pe.GetServerTimeout(),
|
2022-05-23 01:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RoundTrip is Mr. WorldWide. Obviously. See: https://pkg.go.dev/net/http#RoundTripper
|
2022-06-26 02:51:42 +00:00
|
|
|
func (pe *ProxyEngine) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
|
|
return pe.GetHTTPClient().Do(req)
|
2022-05-23 01:20:40 +00:00
|
|
|
}
|