Skip to content

Commit 4b54cd1

Browse files
In SpaProxy, don't fail if there are non-forwardable headers. Fixes aspnet#1543.
1 parent bf1121f commit 4b54cd1

File tree

1 file changed

+15
-3
lines changed
  • src/Microsoft.AspNetCore.SpaServices.Extensions/Proxying

1 file changed

+15
-3
lines changed

src/Microsoft.AspNetCore.SpaServices.Extensions/Proxying/SpaProxy.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ internal static class SpaProxy
2222
private const int DefaultWebSocketBufferSize = 4096;
2323
private const int StreamCopyBufferSize = 81920;
2424

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

2929
public static HttpClient CreateHttpClientForProxy(TimeSpan requestTimeout)
3030
{
@@ -206,7 +206,19 @@ private static async Task<bool> AcceptProxyWebSocketRequest(HttpContext context,
206206
{
207207
if (!NotForwardedWebSocketHeaders.Contains(headerEntry.Key, StringComparer.OrdinalIgnoreCase))
208208
{
209-
client.Options.SetRequestHeader(headerEntry.Key, headerEntry.Value);
209+
try
210+
{
211+
client.Options.SetRequestHeader(headerEntry.Key, headerEntry.Value);
212+
}
213+
catch (ArgumentException)
214+
{
215+
// On net461, certain header names are reserved and can't be set.
216+
// We filter out the known ones via the test above, but there could
217+
// be others arbitrarily set by the client. It's not helpful to
218+
// consider it an error, so just skip non-forwardable headers.
219+
// The perf implications of handling this via a catch aren't an
220+
// issue since this is a dev-time only feature.
221+
}
210222
}
211223
}
212224

0 commit comments

Comments
 (0)