mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
wire up proxier in spdy transport
and delete useless function
This commit is contained in:
parent
f3f666d5f1
commit
652a48d2e7
@ -1034,7 +1034,7 @@ func TestServeExecInContainerIdleTimeout(t *testing.T) {
|
|||||||
|
|
||||||
url := fw.testHTTPServer.URL + "/exec/" + podNamespace + "/" + podName + "/" + expectedContainerName + "?c=ls&c=-a&" + api.ExecStdinParam + "=1"
|
url := fw.testHTTPServer.URL + "/exec/" + podNamespace + "/" + podName + "/" + expectedContainerName + "?c=ls&c=-a&" + api.ExecStdinParam + "=1"
|
||||||
|
|
||||||
upgradeRoundTripper := spdy.NewSpdyRoundTripper(nil, true, true)
|
upgradeRoundTripper := spdy.NewRoundTripper(nil, true, true)
|
||||||
c := &http.Client{Transport: upgradeRoundTripper}
|
c := &http.Client{Transport: upgradeRoundTripper}
|
||||||
|
|
||||||
resp, err := c.Do(makeReq(t, "POST", url, "v4.channel.k8s.io"))
|
resp, err := c.Do(makeReq(t, "POST", url, "v4.channel.k8s.io"))
|
||||||
|
@ -76,19 +76,20 @@ var _ utilnet.TLSClientConfigHolder = &SpdyRoundTripper{}
|
|||||||
var _ httpstream.UpgradeRoundTripper = &SpdyRoundTripper{}
|
var _ httpstream.UpgradeRoundTripper = &SpdyRoundTripper{}
|
||||||
var _ utilnet.Dialer = &SpdyRoundTripper{}
|
var _ utilnet.Dialer = &SpdyRoundTripper{}
|
||||||
|
|
||||||
// NewRoundTripper creates a new SpdyRoundTripper that will use
|
// NewRoundTripper creates a new SpdyRoundTripper that will use the specified
|
||||||
// the specified tlsConfig.
|
// tlsConfig.
|
||||||
func NewRoundTripper(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool) httpstream.UpgradeRoundTripper {
|
func NewRoundTripper(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool) *SpdyRoundTripper {
|
||||||
return NewSpdyRoundTripper(tlsConfig, followRedirects, requireSameHostRedirects)
|
return NewRoundTripperWithProxy(tlsConfig, followRedirects, requireSameHostRedirects, utilnet.NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSpdyRoundTripper creates a new SpdyRoundTripper that will use
|
// NewRoundTripperWithProxy creates a new SpdyRoundTripper that will use the
|
||||||
// the specified tlsConfig. This function is mostly meant for unit tests.
|
// specified tlsConfig and proxy func.
|
||||||
func NewSpdyRoundTripper(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool) *SpdyRoundTripper {
|
func NewRoundTripperWithProxy(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool, proxier func(*http.Request) (*url.URL, error)) *SpdyRoundTripper {
|
||||||
return &SpdyRoundTripper{
|
return &SpdyRoundTripper{
|
||||||
tlsConfig: tlsConfig,
|
tlsConfig: tlsConfig,
|
||||||
followRedirects: followRedirects,
|
followRedirects: followRedirects,
|
||||||
requireSameHostRedirects: requireSameHostRedirects,
|
requireSameHostRedirects: requireSameHostRedirects,
|
||||||
|
proxier: proxier,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,11 +117,7 @@ func (s *SpdyRoundTripper) Dial(req *http.Request) (net.Conn, error) {
|
|||||||
// dial dials the host specified by req, using TLS if appropriate, optionally
|
// dial dials the host specified by req, using TLS if appropriate, optionally
|
||||||
// using a proxy server if one is configured via environment variables.
|
// using a proxy server if one is configured via environment variables.
|
||||||
func (s *SpdyRoundTripper) dial(req *http.Request) (net.Conn, error) {
|
func (s *SpdyRoundTripper) dial(req *http.Request) (net.Conn, error) {
|
||||||
proxier := s.proxier
|
proxyURL, err := s.proxier(req)
|
||||||
if proxier == nil {
|
|
||||||
proxier = utilnet.NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment)
|
|
||||||
}
|
|
||||||
proxyURL, err := proxier(req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ func TestRoundTripAndNewConnection(t *testing.T) {
|
|||||||
t.Fatalf("%s: Error creating request: %s", k, err)
|
t.Fatalf("%s: Error creating request: %s", k, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
spdyTransport := NewSpdyRoundTripper(testCase.clientTLS, redirect, redirect)
|
spdyTransport := NewRoundTripper(testCase.clientTLS, redirect, redirect)
|
||||||
|
|
||||||
var proxierCalled bool
|
var proxierCalled bool
|
||||||
var proxyCalledWithHost string
|
var proxyCalledWithHost string
|
||||||
@ -425,7 +425,7 @@ func TestRoundTripRedirects(t *testing.T) {
|
|||||||
t.Fatalf("Error creating request: %s", err)
|
t.Fatalf("Error creating request: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
spdyTransport := NewSpdyRoundTripper(nil, true, true)
|
spdyTransport := NewRoundTripper(nil, true, true)
|
||||||
client := &http.Client{Transport: spdyTransport}
|
client := &http.Client{Transport: spdyTransport}
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
@ -38,7 +38,11 @@ func RoundTripperFor(config *restclient.Config) (http.RoundTripper, Upgrader, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
upgradeRoundTripper := spdy.NewRoundTripper(tlsConfig, true, false)
|
proxy := http.ProxyFromEnvironment
|
||||||
|
if config.Proxy != nil {
|
||||||
|
proxy = config.Proxy
|
||||||
|
}
|
||||||
|
upgradeRoundTripper := spdy.NewRoundTripperWithProxy(tlsConfig, true, false, proxy)
|
||||||
wrapper, err := restclient.HTTPWrappersForConfig(config, upgradeRoundTripper)
|
wrapper, err := restclient.HTTPWrappersForConfig(config, upgradeRoundTripper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user