Skip to content

Commit dd5efcb

Browse files
gedemgedem
authored andcommitted
ConnectionId default header set for proxy client
1 parent 5809399 commit dd5efcb

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/NetCoreStack.WebSockets.ProxyClient/ClientWebSocketConnector.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,29 @@ public async Task ConnectAsync()
8585
}
8686
}
8787

88+
private ArraySegment<byte> CreateTextSegment(WebSocketMessageContext context)
89+
{
90+
if (context == null)
91+
{
92+
throw new ArgumentNullException(nameof(context));
93+
}
94+
95+
object connectionId = string.Empty;
96+
if (context.Header.TryGetValue(SocketsConstants.ConnectionId, out connectionId))
97+
{
98+
var id = connectionId as string;
99+
if (string.IsNullOrEmpty(id))
100+
throw new InvalidOperationException(nameof(connectionId));
101+
}
102+
else
103+
context.Header.Add(SocketsConstants.ConnectionId, ConnectionId);
104+
105+
return context.ToSegment();
106+
}
107+
88108
public async Task SendAsync(WebSocketMessageContext context)
89109
{
90-
var segments = context.ToSegment();
110+
var segments = CreateTextSegment(context);
91111
await _webSocket.SendAsync(segments, WebSocketMessageType.Text, true, CancellationToken.None);
92112
}
93113

src/NetCoreStack.WebSockets/Internal/SocketsConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public static class SocketsConstants
66
public const int ChunkSize = 1024 * 4;
77
public const string CompressedKey = "Compressed";
88
public const string ConnectorName = "ConnectorName";
9+
public const string ConnectionId = "ConnectionId";
910
}
1011
}

0 commit comments

Comments
 (0)