mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-04 01:53:09 +03:00
proxy: initialize ReverseProxy.Transport earlier and fix TCP connection leak (#2134)
This commit is contained in:
parent
2922d09bef
commit
fe664c00ff
1 changed files with 10 additions and 17 deletions
|
@ -85,7 +85,6 @@ type ReverseProxy struct {
|
||||||
Director func(*http.Request)
|
Director func(*http.Request)
|
||||||
|
|
||||||
// The transport used to perform proxy requests.
|
// The transport used to perform proxy requests.
|
||||||
// If nil, http.DefaultTransport is used.
|
|
||||||
Transport http.RoundTripper
|
Transport http.RoundTripper
|
||||||
|
|
||||||
// FlushInterval specifies the flush interval
|
// FlushInterval specifies the flush interval
|
||||||
|
@ -274,6 +273,15 @@ func NewSingleHostReverseProxy(target *url.URL, without string, keepalive int, t
|
||||||
http2.ConfigureTransport(transport)
|
http2.ConfigureTransport(transport)
|
||||||
}
|
}
|
||||||
rp.Transport = transport
|
rp.Transport = transport
|
||||||
|
} else {
|
||||||
|
transport := &http.Transport{
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
|
Dial: rp.dialer.Dial,
|
||||||
|
}
|
||||||
|
if httpserver.HTTP2 {
|
||||||
|
http2.ConfigureTransport(transport)
|
||||||
|
}
|
||||||
|
rp.Transport = transport
|
||||||
}
|
}
|
||||||
return rp
|
return rp
|
||||||
}
|
}
|
||||||
|
@ -282,18 +290,7 @@ func NewSingleHostReverseProxy(target *url.URL, without string, keepalive int, t
|
||||||
// when it is OK for upstream to be using a bad certificate,
|
// when it is OK for upstream to be using a bad certificate,
|
||||||
// since this transport skips verification.
|
// since this transport skips verification.
|
||||||
func (rp *ReverseProxy) UseInsecureTransport() {
|
func (rp *ReverseProxy) UseInsecureTransport() {
|
||||||
if rp.Transport == nil {
|
if transport, ok := rp.Transport.(*http.Transport); ok {
|
||||||
transport := &http.Transport{
|
|
||||||
Proxy: http.ProxyFromEnvironment,
|
|
||||||
Dial: rp.dialer.Dial,
|
|
||||||
TLSHandshakeTimeout: defaultCryptoHandshakeTimeout,
|
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
||||||
}
|
|
||||||
if httpserver.HTTP2 {
|
|
||||||
http2.ConfigureTransport(transport)
|
|
||||||
}
|
|
||||||
rp.Transport = transport
|
|
||||||
} else if transport, ok := rp.Transport.(*http.Transport); ok {
|
|
||||||
if transport.TLSClientConfig == nil {
|
if transport.TLSClientConfig == nil {
|
||||||
transport.TLSClientConfig = &tls.Config{}
|
transport.TLSClientConfig = &tls.Config{}
|
||||||
}
|
}
|
||||||
|
@ -315,10 +312,6 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
|
||||||
transport := rp.Transport
|
transport := rp.Transport
|
||||||
if requestIsWebsocket(outreq) {
|
if requestIsWebsocket(outreq) {
|
||||||
transport = newConnHijackerTransport(transport)
|
transport = newConnHijackerTransport(transport)
|
||||||
} else if transport == nil {
|
|
||||||
transport = &http.Transport{
|
|
||||||
Dial: rp.dialer.Dial,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rp.Director(outreq)
|
rp.Director(outreq)
|
||||||
|
|
Loading…
Reference in a new issue