Added proxy

addon-dailer
alex 2 years ago
parent ead30d6248
commit 650f1f0714

@ -105,10 +105,17 @@ func (connCtx *ConnContext) initHttpServerConn() {
return return
} }
var useProxy func(*http.Request) (*url.URL, error)
if len(connCtx.proxy.Opts.Upstream) > 0 {
upstreamUrl, _ := url.Parse(connCtx.proxy.Opts.Upstream)
useProxy = http.ProxyURL(upstreamUrl)
} else {
useProxy = http.ProxyFromEnvironment
}
serverConn := newServerConn() serverConn := newServerConn()
serverConn.client = &http.Client{ serverConn.client = &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment, Proxy: useProxy,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
c, err := (&net.Dialer{}).DialContext(ctx, network, addr) c, err := (&net.Dialer{}).DialContext(ctx, network, addr)
if err != nil { if err != nil {

@ -16,6 +16,7 @@ type Options struct {
StreamLargeBodies int64 // 当请求或响应体大于此字节时,转为 stream 模式 StreamLargeBodies int64 // 当请求或响应体大于此字节时,转为 stream 模式
SslInsecure bool SslInsecure bool
CaRootPath string CaRootPath string
Upstream string
} }
type Proxy struct { type Proxy struct {

Loading…
Cancel
Save