Skip to content

Commit 7aa91ff

Browse files
authored
SpaProxy: Fix proxying of WebSocket protocol (#23250)
1 parent f5709b4 commit 7aa91ff

File tree

1 file changed

+5
-1
lines changed
  • src/Middleware/SpaServices.Extensions/src/Proxying

1 file changed

+5
-1
lines changed

src/Middleware/SpaServices.Extensions/src/Proxying/SpaProxy.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static class SpaProxy
2727

2828
// Don't forward User-Agent/Accept because of https://github.com/aspnet/JavaScriptServices/issues/1469
2929
// Others just aren't applicable in proxy scenarios
30-
private static readonly string[] NotForwardedWebSocketHeaders = new[] { "Accept", "Connection", "Host", "User-Agent", "Upgrade", "Sec-WebSocket-Key", "Sec-WebSocket-Version" };
30+
private static readonly string[] NotForwardedWebSocketHeaders = new[] { "Accept", "Connection", "Host", "User-Agent", "Upgrade", "Sec-WebSocket-Key", "Sec-WebSocket-Protocol", "Sec-WebSocket-Version" };
3131

3232
public static HttpClient CreateHttpClientForProxy(TimeSpan requestTimeout)
3333
{
@@ -209,6 +209,10 @@ private static async Task<bool> AcceptProxyWebSocketRequest(HttpContext context,
209209

210210
using (var client = new ClientWebSocket())
211211
{
212+
foreach (var protocol in context.WebSockets.WebSocketRequestedProtocols)
213+
{
214+
client.Options.AddSubProtocol(protocol);
215+
}
212216
foreach (var headerEntry in context.Request.Headers)
213217
{
214218
if (!NotForwardedWebSocketHeaders.Contains(headerEntry.Key, StringComparer.OrdinalIgnoreCase))

0 commit comments

Comments
 (0)