From 1d78d9b694585774800088756e4115f9d0e7b5cf Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Tue, 3 Aug 2021 13:46:49 +0300 Subject: [PATCH 1/2] Fixed http to ws prefix --- src/KubernetesCluster.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/KubernetesCluster.php b/src/KubernetesCluster.php index 2920c86f..1d048734 100644 --- a/src/KubernetesCluster.php +++ b/src/KubernetesCluster.php @@ -289,11 +289,17 @@ protected function makeRequest(string $method, string $path, string $payload = ' */ protected function makeWsRequest(string $path, Closure $callback = null, array $query = ['pretty' => 1]) { - $url = str_replace( - ['https://', 'http://'], - ['wss://', 'ws://'], - $this->getCallableUrl($path, $query) - ); + $url = $this->getCallableUrl($path, $query); + + // Replace the HTTP protocol prefixes with WS protocols. + $replaces = [ + 'https://' => 'wss://', + 'http://' => 'ws://', + ]; + + foreach ($replaces as $search => $replace) { + $url = Str::replaceFirst($search, $replace, $url); + } [$loop, $ws] = $this->getWsClient($url); From df18f5a6253a2c74542610d868d14c4a401580cd Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Tue, 3 Aug 2021 14:09:42 +0300 Subject: [PATCH 2/2] Added startsWith() check --- src/KubernetesCluster.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/KubernetesCluster.php b/src/KubernetesCluster.php index 1d048734..1c5cb707 100644 --- a/src/KubernetesCluster.php +++ b/src/KubernetesCluster.php @@ -298,7 +298,9 @@ protected function makeWsRequest(string $path, Closure $callback = null, array $ ]; foreach ($replaces as $search => $replace) { - $url = Str::replaceFirst($search, $replace, $url); + if (Str::startsWith($url, $search)) { + $url = Str::replaceFirst($search, $replace, $url); + } } [$loop, $ws] = $this->getWsClient($url);