diff --git a/pkg/util/httpstream/httpstream.go b/pkg/util/httpstream/httpstream.go index a32fce5a0..8054b9867 100644 --- a/pkg/util/httpstream/httpstream.go +++ b/pkg/util/httpstream/httpstream.go @@ -116,6 +116,15 @@ func IsUpgradeFailure(err error) bool { return errors.As(err, &upgradeErr) } +// isHTTPSProxyError returns true if error is Gorilla/Websockets HTTPS Proxy dial error; +// false otherwise (see https://github.com/kubernetes/kubernetes/issues/126134). +func IsHTTPSProxyError(err error) bool { + if err == nil { + return false + } + return strings.Contains(err.Error(), "proxy: unknown scheme: https") +} + // IsUpgradeRequest returns true if the given request is a connection upgrade request func IsUpgradeRequest(req *http.Request) bool { for _, h := range req.Header[http.CanonicalHeaderKey(HeaderConnection)] { diff --git a/pkg/util/httpstream/httpstream_test.go b/pkg/util/httpstream/httpstream_test.go index 11fb92863..6254e9709 100644 --- a/pkg/util/httpstream/httpstream_test.go +++ b/pkg/util/httpstream/httpstream_test.go @@ -168,3 +168,32 @@ func TestIsUpgradeFailureError(t *testing.T) { }) } } + +func TestIsHTTPSProxyError(t *testing.T) { + testCases := map[string]struct { + err error + expected bool + }{ + "nil error should return false": { + err: nil, + expected: false, + }, + "Not HTTPS proxy error should return false": { + err: errors.New("this is not an upgrade error"), + expected: false, + }, + "HTTPS proxy error should return true": { + err: errors.New("proxy: unknown scheme: https"), + expected: true, + }, + } + + for name, test := range testCases { + t.Run(name, func(t *testing.T) { + actual := IsHTTPSProxyError(test.err) + if test.expected != actual { + t.Errorf("expected HTTPS proxy error %t, got %t", test.expected, actual) + } + }) + } +}