Skip to content

Commit c8ad8f8

Browse files
qmfrederikbrendandburns
authored andcommitted
Fix an issue where StreamConnectAsync would crash if the credentials were not set (#132)
1 parent 801455c commit c8ad8f8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Kubernetes.WebSocket.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,16 @@ public partial class Kubernetes
216216
webSocketBuilder.AddClientCertificate(cert);
217217
}
218218

219-
HttpRequestMessage message = new HttpRequestMessage();
220-
await this.Credentials.ProcessHttpRequestAsync(message, cancellationToken);
221-
222-
foreach (var _header in message.Headers)
219+
if (this.Credentials != null)
223220
{
224-
webSocketBuilder.SetRequestHeader(_header.Key, string.Join(" ", _header.Value));
221+
// Copy the default (credential-related) request headers from the HttpClient to the WebSocket
222+
HttpRequestMessage message = new HttpRequestMessage();
223+
await this.Credentials.ProcessHttpRequestAsync(message, cancellationToken);
224+
225+
foreach (var _header in message.Headers)
226+
{
227+
webSocketBuilder.SetRequestHeader(_header.Key, string.Join(" ", _header.Value));
228+
}
225229
}
226230

227231
#if NETCOREAPP2_1

0 commit comments

Comments
 (0)