From 4eebc166bfa9bb84dcb3da3656d0984aeddb4a07 Mon Sep 17 00:00:00 2001 From: Christopher Haws Date: Sun, 10 Nov 2019 16:06:14 -0800 Subject: [PATCH] Add ignored http headers to SpaProxy (#16863) * Add ignored http headers to SpaProxy * Remove `cookie` header from NotForwardedHttpHeaders --- .../SpaServices.Extensions/src/Proxying/SpaProxy.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Middleware/SpaServices.Extensions/src/Proxying/SpaProxy.cs b/src/Middleware/SpaServices.Extensions/src/Proxying/SpaProxy.cs index 91c6b72f96..84f30df2de 100644 --- a/src/Middleware/SpaServices.Extensions/src/Proxying/SpaProxy.cs +++ b/src/Middleware/SpaServices.Extensions/src/Proxying/SpaProxy.cs @@ -22,6 +22,9 @@ namespace Microsoft.AspNetCore.SpaServices.Extensions.Proxy private const int DefaultWebSocketBufferSize = 4096; private const int StreamCopyBufferSize = 81920; + // https://github.com/aspnet/AspNetCore/issues/16797 + private static readonly string[] NotForwardedHttpHeaders = new[] { "Connection" }; + // Don't forward User-Agent/Accept because of https://github.com/aspnet/JavaScriptServices/issues/1469 // 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" }; @@ -132,6 +135,11 @@ namespace Microsoft.AspNetCore.SpaServices.Extensions.Proxy // Copy the request headers foreach (var header in request.Headers) { + if (NotForwardedHttpHeaders.Contains(header.Key, StringComparer.OrdinalIgnoreCase)) + { + continue; + } + if (!requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()) && requestMessage.Content != null) { requestMessage.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray());