From 873cfa9adf35df5a30c3b990ac8005f3f70fccea Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Wed, 21 Feb 2018 14:02:19 +0000 Subject: [PATCH] In SpaProxy, don't fail if there are non-forwardable headers. Fixes #1543. --- .../Proxying/SpaProxy.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.SpaServices.Extensions/Proxying/SpaProxy.cs b/src/Microsoft.AspNetCore.SpaServices.Extensions/Proxying/SpaProxy.cs index c675625..bda454a 100644 --- a/src/Microsoft.AspNetCore.SpaServices.Extensions/Proxying/SpaProxy.cs +++ b/src/Microsoft.AspNetCore.SpaServices.Extensions/Proxying/SpaProxy.cs @@ -22,9 +22,9 @@ namespace Microsoft.AspNetCore.SpaServices.Extensions.Proxy private const int DefaultWebSocketBufferSize = 4096; private const int StreamCopyBufferSize = 81920; - // Don't forward User-Agent 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 - private static readonly string[] NotForwardedWebSocketHeaders = new[] { "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-Version" }; public static HttpClient CreateHttpClientForProxy(TimeSpan requestTimeout) { @@ -206,7 +206,19 @@ namespace Microsoft.AspNetCore.SpaServices.Extensions.Proxy { if (!NotForwardedWebSocketHeaders.Contains(headerEntry.Key, StringComparer.OrdinalIgnoreCase)) { - client.Options.SetRequestHeader(headerEntry.Key, headerEntry.Value); + try + { + client.Options.SetRequestHeader(headerEntry.Key, headerEntry.Value); + } + catch (ArgumentException) + { + // On net461, certain header names are reserved and can't be set. + // We filter out the known ones via the test above, but there could + // be others arbitrarily set by the client. It's not helpful to + // consider it an error, so just skip non-forwardable headers. + // The perf implications of handling this via a catch aren't an + // issue since this is a dev-time only feature. + } } }