summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go49
1 files changed, 43 insertions, 6 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go b/vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go
index 6309fbc26..4cb1cfadc 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/httpstream/spdy/roundtripper.go
@@ -30,6 +30,7 @@ import (
"net/http/httputil"
"net/url"
"strings"
+ "time"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -70,6 +71,9 @@ type SpdyRoundTripper struct {
// requireSameHostRedirects restricts redirect following to only follow redirects to the same host
// as the original request.
requireSameHostRedirects bool
+ // pingPeriod is a period for sending Ping frames over established
+ // connections.
+ pingPeriod time.Duration
}
var _ utilnet.TLSClientConfigHolder = &SpdyRoundTripper{}
@@ -79,20 +83,53 @@ var _ utilnet.Dialer = &SpdyRoundTripper{}
// NewRoundTripper creates a new SpdyRoundTripper that will use the specified
// tlsConfig.
func NewRoundTripper(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool) *SpdyRoundTripper {
- return NewRoundTripperWithProxy(tlsConfig, followRedirects, requireSameHostRedirects, utilnet.NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment))
+ return NewRoundTripperWithConfig(RoundTripperConfig{
+ TLS: tlsConfig,
+ FollowRedirects: followRedirects,
+ RequireSameHostRedirects: requireSameHostRedirects,
+ })
}
// NewRoundTripperWithProxy creates a new SpdyRoundTripper that will use the
// specified tlsConfig and proxy func.
func NewRoundTripperWithProxy(tlsConfig *tls.Config, followRedirects, requireSameHostRedirects bool, proxier func(*http.Request) (*url.URL, error)) *SpdyRoundTripper {
+ return NewRoundTripperWithConfig(RoundTripperConfig{
+ TLS: tlsConfig,
+ FollowRedirects: followRedirects,
+ RequireSameHostRedirects: requireSameHostRedirects,
+ Proxier: proxier,
+ })
+}
+
+// NewRoundTripperWithProxy creates a new SpdyRoundTripper with the specified
+// configuration.
+func NewRoundTripperWithConfig(cfg RoundTripperConfig) *SpdyRoundTripper {
+ if cfg.Proxier == nil {
+ cfg.Proxier = utilnet.NewProxierWithNoProxyCIDR(http.ProxyFromEnvironment)
+ }
return &SpdyRoundTripper{
- tlsConfig: tlsConfig,
- followRedirects: followRedirects,
- requireSameHostRedirects: requireSameHostRedirects,
- proxier: proxier,
+ tlsConfig: cfg.TLS,
+ followRedirects: cfg.FollowRedirects,
+ requireSameHostRedirects: cfg.RequireSameHostRedirects,
+ proxier: cfg.Proxier,
+ pingPeriod: cfg.PingPeriod,
}
}
+// RoundTripperConfig is a set of options for an SpdyRoundTripper.
+type RoundTripperConfig struct {
+ // TLS configuration used by the round tripper.
+ TLS *tls.Config
+ // Proxier is a proxy function invoked on each request. Optional.
+ Proxier func(*http.Request) (*url.URL, error)
+ // PingPeriod is a period for sending SPDY Pings on the connection.
+ // Optional.
+ PingPeriod time.Duration
+
+ FollowRedirects bool
+ RequireSameHostRedirects bool
+}
+
// TLSClientConfig implements pkg/util/net.TLSClientConfigHolder for proper TLS checking during
// proxying with a spdy roundtripper.
func (s *SpdyRoundTripper) TLSClientConfig() *tls.Config {
@@ -316,7 +353,7 @@ func (s *SpdyRoundTripper) NewConnection(resp *http.Response) (httpstream.Connec
return nil, fmt.Errorf("unable to upgrade connection: %s", responseError)
}
- return NewClientConnection(s.conn)
+ return NewClientConnectionWithPings(s.conn, s.pingPeriod)
}
// statusScheme is private scheme for the decoding here until someone fixes the TODO in NewConnection