2022-05-23 01:20:40 +00:00
|
|
|
package prox5
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto/tls"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetHTTPClient retrieves a pointer to an http.Client powered by MysteryDialer.
|
2022-09-22 23:28:28 +00:00
|
|
|
func (pe *Swamp) GetHTTPClient() *http.Client {
|
2022-08-31 18:49:06 +00:00
|
|
|
// var htp func(*http.Request) (*url.URL, error)
|
2022-05-23 01:20:40 +00:00
|
|
|
var dctx func(ctx context.Context, network string, addr string) (net.Conn, error)
|
2022-08-31 18:49:06 +00:00
|
|
|
// if httun, htok := pe.GetHTTPTunnel(); htok {
|
|
|
|
// httprox, uerr := url.Parse("http://" + httun.Endpoint)
|
|
|
|
// if uerr == nil {
|
|
|
|
// htp = http.ProxyURL(httprox)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if htp == nil {
|
|
|
|
dctx = pe.DialContext
|
|
|
|
// }
|
2022-05-23 01:20:40 +00:00
|
|
|
return &http.Client{
|
|
|
|
Transport: &http.Transport{
|
2022-08-31 18:49:06 +00:00
|
|
|
// Proxy: htp,
|
2022-05-23 01:20:40 +00:00
|
|
|
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-09-22 23:28:28 +00:00
|
|
|
func (pe *Swamp) RoundTrip(req *http.Request) (*http.Response, error) {
|
2022-06-26 02:51:42 +00:00
|
|
|
return pe.GetHTTPClient().Do(req)
|
2022-05-23 01:20:40 +00:00
|
|
|
}
|