Skip to content

Commit a8f449e

Browse files
seans3k8s-publishing-bot
authored andcommitted
Falls back to SPDY for gorilla/websocket https proxy error
Kubernetes-commit: 9d560540c5268e0e2aebf5306907494cf522c260
1 parent 62791ec commit a8f449e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pkg/util/httpstream/httpstream.go

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ func IsUpgradeFailure(err error) bool {
116116
return errors.As(err, &upgradeErr)
117117
}
118118

119+
// isHTTPSProxyError returns true if error is Gorilla/Websockets HTTPS Proxy dial error;
120+
// false otherwise (see https://github.com/kubernetes/kubernetes/issues/126134).
121+
func IsHTTPSProxyError(err error) bool {
122+
if err == nil {
123+
return false
124+
}
125+
return strings.Contains(err.Error(), "proxy: unknown scheme: https")
126+
}
127+
119128
// IsUpgradeRequest returns true if the given request is a connection upgrade request
120129
func IsUpgradeRequest(req *http.Request) bool {
121130
for _, h := range req.Header[http.CanonicalHeaderKey(HeaderConnection)] {

pkg/util/httpstream/httpstream_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,32 @@ func TestIsUpgradeFailureError(t *testing.T) {
168168
})
169169
}
170170
}
171+
172+
func TestIsHTTPSProxyError(t *testing.T) {
173+
testCases := map[string]struct {
174+
err error
175+
expected bool
176+
}{
177+
"nil error should return false": {
178+
err: nil,
179+
expected: false,
180+
},
181+
"Not HTTPS proxy error should return false": {
182+
err: errors.New("this is not an upgrade error"),
183+
expected: false,
184+
},
185+
"HTTPS proxy error should return true": {
186+
err: errors.New("proxy: unknown scheme: https"),
187+
expected: true,
188+
},
189+
}
190+
191+
for name, test := range testCases {
192+
t.Run(name, func(t *testing.T) {
193+
actual := IsHTTPSProxyError(test.err)
194+
if test.expected != actual {
195+
t.Errorf("expected HTTPS proxy error %t, got %t", test.expected, actual)
196+
}
197+
})
198+
}
199+
}

0 commit comments

Comments
 (0)