SpaProxy: Fix proxying of WebSocket protocol (#23250)
This commit is contained in:
parent
f5709b4080
commit
7aa91ffd62
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNetCore.SpaServices.Extensions.Proxy
|
||||||
|
|
||||||
// Don't forward User-Agent/Accept because of https://github.com/aspnet/JavaScriptServices/issues/1469
|
// Don't forward User-Agent/Accept because of https://github.com/aspnet/JavaScriptServices/issues/1469
|
||||||
// Others just aren't applicable in proxy scenarios
|
// Others just aren't applicable in proxy scenarios
|
||||||
private static readonly string[] NotForwardedWebSocketHeaders = new[] { "Accept", "Connection", "Host", "User-Agent", "Upgrade", "Sec-WebSocket-Key", "Sec-WebSocket-Version" };
|
private static readonly string[] NotForwardedWebSocketHeaders = new[] { "Accept", "Connection", "Host", "User-Agent", "Upgrade", "Sec-WebSocket-Key", "Sec-WebSocket-Protocol", "Sec-WebSocket-Version" };
|
||||||
|
|
||||||
public static HttpClient CreateHttpClientForProxy(TimeSpan requestTimeout)
|
public static HttpClient CreateHttpClientForProxy(TimeSpan requestTimeout)
|
||||||
{
|
{
|
||||||
|
|
@ -209,6 +209,10 @@ namespace Microsoft.AspNetCore.SpaServices.Extensions.Proxy
|
||||||
|
|
||||||
using (var client = new ClientWebSocket())
|
using (var client = new ClientWebSocket())
|
||||||
{
|
{
|
||||||
|
foreach (var protocol in context.WebSockets.WebSocketRequestedProtocols)
|
||||||
|
{
|
||||||
|
client.Options.AddSubProtocol(protocol);
|
||||||
|
}
|
||||||
foreach (var headerEntry in context.Request.Headers)
|
foreach (var headerEntry in context.Request.Headers)
|
||||||
{
|
{
|
||||||
if (!NotForwardedWebSocketHeaders.Contains(headerEntry.Key, StringComparer.OrdinalIgnoreCase))
|
if (!NotForwardedWebSocketHeaders.Contains(headerEntry.Key, StringComparer.OrdinalIgnoreCase))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue