diff --git a/proxy/connection.go b/proxy/connection.go index cb99e9d..f97a081 100644 --- a/proxy/connection.go +++ b/proxy/connection.go @@ -105,10 +105,17 @@ func (connCtx *ConnContext) initHttpServerConn() { 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.client = &http.Client{ Transport: &http.Transport{ - Proxy: http.ProxyFromEnvironment, + Proxy: useProxy, DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { c, err := (&net.Dialer{}).DialContext(ctx, network, addr) if err != nil { diff --git a/proxy/proxy.go b/proxy/proxy.go index 956653f..1bf8f20 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -16,6 +16,7 @@ type Options struct { StreamLargeBodies int64 // 当请求或响应体大于此字节时,转为 stream 模式 SslInsecure bool CaRootPath string + Upstream string } type Proxy struct {