From 4b230ec419f1087124be4c4b4e5c2cec6f040210 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Fri, 22 Mar 2019 15:36:57 -0700 Subject: [PATCH] Copy EndpointFeature when using LongPolling (#8730) --- .../src/Internal/HttpConnectionDispatcher.cs | 6 +++++- .../Http.Connections/test/HttpConnectionDispatcherTests.cs | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs index a1790f9423..c10dc10131 100644 --- a/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs +++ b/src/SignalR/common/Http.Connections/src/Internal/HttpConnectionDispatcher.cs @@ -12,6 +12,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Http.Connections.Internal.Transports; +using Microsoft.AspNetCore.Http.Endpoints; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Internal; using Microsoft.Extensions.Logging; @@ -567,7 +568,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal requestFeature.PathBase = existingRequestFeature.PathBase; requestFeature.QueryString = existingRequestFeature.QueryString; requestFeature.RawTarget = existingRequestFeature.RawTarget; - var requestHeaders = new Dictionary(existingRequestFeature.Headers.Count, StringComparer.Ordinal); + var requestHeaders = new Dictionary(existingRequestFeature.Headers.Count, StringComparer.OrdinalIgnoreCase); foreach (var header in existingRequestFeature.Headers) { requestHeaders[header.Key] = header.Value; @@ -600,6 +601,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal var newHttpContext = new DefaultHttpContext(features); newHttpContext.TraceIdentifier = context.TraceIdentifier; + var endpointFeature = context.Features.Get(); + newHttpContext.SetEndpoint(endpointFeature?.Endpoint); + CloneUser(newHttpContext, context); // Making request services function property could be tricky and expensive as it would require diff --git a/src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs b/src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs index a328289a8b..668229043a 100644 --- a/src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs +++ b/src/SignalR/common/Http.Connections/test/HttpConnectionDispatcherTests.cs @@ -19,6 +19,7 @@ using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Connections.Features; using Microsoft.AspNetCore.Http.Connections.Internal; using Microsoft.AspNetCore.Http.Connections.Internal.Transports; +using Microsoft.AspNetCore.Http.Endpoints; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.SignalR.Tests; @@ -627,6 +628,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests context.Connection.LocalPort = 4563; context.Connection.RemoteIpAddress = IPAddress.IPv6Any; context.Connection.RemotePort = 43456; + context.SetEndpoint(new Endpoint(null, null, "TestName")); var builder = new ConnectionBuilder(services.BuildServiceProvider()); builder.UseConnectionHandler(); @@ -679,6 +681,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests Assert.Equal(Stream.Null, connectionHttpContext.Response.Body); Assert.NotNull(connectionHttpContext.Response.Headers); Assert.Equal("application/xml", connectionHttpContext.Response.ContentType); + var endpointFeature = connectionHttpContext.Features.Get(); + Assert.NotNull(endpointFeature); + Assert.Equal("TestName", endpointFeature.Endpoint.DisplayName); } } }