Skip to content

Commit

Permalink
NatsWebSocketOpts improvements (#610)
Browse files Browse the repository at this point in the history
* Fence added, an occurs exceptions when add headers to blazor
  • Loading branch information
Ivandemidov00 committed Sep 8, 2024
1 parent 4da55d4 commit e6b9d1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/NATS.Client.Core/Internal/DotnetRuntimeConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Runtime.InteropServices;

namespace NATS.Client.Core.Internal;

internal static class DotnetRuntimeConstants
{
public static readonly OSPlatform BrowserPlatform = OSPlatform.Create("Browser");
}
4 changes: 2 additions & 2 deletions src/NATS.Client.Core/NatsWebSocketOpts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.WebSockets;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Primitives;
using NATS.Client.Core.Internal;

Expand Down Expand Up @@ -32,8 +33,7 @@ internal async ValueTask ApplyClientWebSocketOptionsAsync(
NatsTlsOpts tlsOpts,
CancellationToken cancellationToken)
{
// todo: test that this doesn't throw in Blazor, otherwise we need a way to detect Blazor and skip
if (RequestHeaders != null)
if (RequestHeaders != null && !RuntimeInformation.IsOSPlatform(DotnetRuntimeConstants.BrowserPlatform))
{
foreach (var entry in RequestHeaders)
{
Expand Down

0 comments on commit e6b9d1c

Please sign in to comment.