From 3609f20fc02bb885fffcd477849fd88007086659 Mon Sep 17 00:00:00 2001 From: lionsoft Date: Thu, 10 Feb 2022 12:31:33 +0200 Subject: [PATCH] fix WebSocket-proxy error when copying protected headers --- .gitignore | 3 ++- src/Core/Extensions/Ws.cs | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5a1150c..07e7156 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,5 @@ build/ # MSTest test Results [Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* \ No newline at end of file +[Bb]uild[Ll]og.* +/src/Core/Properties/launchSettings.json diff --git a/src/Core/Extensions/Ws.cs b/src/Core/Extensions/Ws.cs index 7d05481..fdeea2a 100644 --- a/src/Core/Extensions/Ws.cs +++ b/src/Core/Extensions/Ws.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Net; using System.Net.WebSockets; using System.Text; using System.Threading; @@ -39,7 +40,13 @@ internal static async Task ExecuteWsProxyOperationAsync(this HttpContext context foreach (var headerEntry in context.Request.Headers) { if (!Helpers.WebSocketNotForwardedHeaders.Contains(headerEntry.Key, StringComparer.OrdinalIgnoreCase)) - socketToEndpoint.Options.SetRequestHeader(headerEntry.Key, headerEntry.Value); + { + if (!WebHeaderCollection.IsRestricted(headerEntry.Key)) + { + socketToEndpoint.Options.SetRequestHeader(headerEntry.Key, headerEntry.Value); + } + } + } if(options?.BeforeConnect != null)