Skip to content

Commit

Permalink
Falls back to SPDY for gorilla/websocket https proxy error
Browse files Browse the repository at this point in the history
Kubernetes-commit: 9d560540c5268e0e2aebf5306907494cf522c260
  • Loading branch information
seans3 authored and k8s-publishing-bot committed Jul 19, 2024
1 parent 62791ec commit a8f449e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/util/httpstream/httpstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)] {
Expand Down
29 changes: 29 additions & 0 deletions pkg/util/httpstream/httpstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

0 comments on commit a8f449e

Please sign in to comment.