From 129a5ad47409d0b35dee6621f876f767b7f79874 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 13 Jan 2016 10:42:42 -0800 Subject: [PATCH] Bypass LibuvStream if no ConnectionFilter wraps it --- .../Properties/AssemblyInfo.cs | 1 + .../Http/Connection.cs | 19 ++++++++++++++----- .../EngineTests.cs | 15 ++++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs b/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs index 7c3af07032..a8f71a20f0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs +++ b/src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs @@ -5,5 +5,6 @@ using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: AssemblyMetadata("Serviceable", "True")] [assembly: NeutralResourcesLanguage("en-us")] diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 6f2ea40f27..96b6c0b93a 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -23,6 +23,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly UvStreamHandle _socket; private Frame _frame; private ConnectionFilterContext _filterContext; + private LibuvStream _libuvStream; private readonly long _connectionId; private readonly SocketInput _rawSocketInput; @@ -70,11 +71,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } else { - var libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput); + _libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput); _filterContext = new ConnectionFilterContext { - Connection = libuvStream, + Connection = _libuvStream, Address = ServerAddress }; @@ -124,10 +125,18 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private void ApplyConnectionFilter() { - var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool); + if (_filterContext.Connection != _libuvStream) + { + var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool); - SocketInput = filteredStreamAdapter.SocketInput; - SocketOutput = filteredStreamAdapter.SocketOutput; + SocketInput = filteredStreamAdapter.SocketInput; + SocketOutput = filteredStreamAdapter.SocketOutput; + } + else + { + SocketInput = _rawSocketInput; + SocketOutput = _rawSocketOutput; + } _frame = CreateFrame(); _frame.Start(); diff --git a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs index 76b65c58f1..b18736daa8 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Linq; using System.IO; +using System.Linq; using System.Net; using System.Net.Sockets; using System.Text; @@ -13,7 +13,7 @@ using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel.Filter; -using Microsoft.AspNet.Server.Kestrel.Http; +using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Testing.xunit; using Microsoft.Extensions.Logging; using Xunit; @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { new TestServiceContext { - ConnectionFilter = new NoOpConnectionFilter() + ConnectionFilter = new PassThroughConnectionFilter() } } }; @@ -1177,5 +1177,14 @@ namespace Microsoft.AspNet.Server.KestrelTests } } } + + private class PassThroughConnectionFilter : IConnectionFilter + { + public Task OnConnectionAsync(ConnectionFilterContext context) + { + context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger()); + return TaskUtilities.CompletedTask; + } + } } }