Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 129a5ad

Browse files
committed
Bypass LibuvStream if no ConnectionFilter wraps it
1 parent e5ad019 commit 129a5ad

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/Microsoft.AspNet.Server.Kestrel.Https/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
using System.Resources;
66
using System.Runtime.CompilerServices;
77

8+
[assembly: InternalsVisibleTo("Microsoft.AspNet.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
89
[assembly: AssemblyMetadata("Serviceable", "True")]
910
[assembly: NeutralResourcesLanguage("en-us")]

src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Connection : ConnectionContext, IConnectionControl
2323
private readonly UvStreamHandle _socket;
2424
private Frame _frame;
2525
private ConnectionFilterContext _filterContext;
26+
private LibuvStream _libuvStream;
2627
private readonly long _connectionId;
2728

2829
private readonly SocketInput _rawSocketInput;
@@ -70,11 +71,11 @@ public void Start()
7071
}
7172
else
7273
{
73-
var libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput);
74+
_libuvStream = new LibuvStream(_rawSocketInput, _rawSocketOutput);
7475

7576
_filterContext = new ConnectionFilterContext
7677
{
77-
Connection = libuvStream,
78+
Connection = _libuvStream,
7879
Address = ServerAddress
7980
};
8081

@@ -124,10 +125,18 @@ public void Abort()
124125

125126
private void ApplyConnectionFilter()
126127
{
127-
var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool);
128+
if (_filterContext.Connection != _libuvStream)
129+
{
130+
var filteredStreamAdapter = new FilteredStreamAdapter(_filterContext.Connection, Memory2, Log, ThreadPool);
128131

129-
SocketInput = filteredStreamAdapter.SocketInput;
130-
SocketOutput = filteredStreamAdapter.SocketOutput;
132+
SocketInput = filteredStreamAdapter.SocketInput;
133+
SocketOutput = filteredStreamAdapter.SocketOutput;
134+
}
135+
else
136+
{
137+
SocketInput = _rawSocketInput;
138+
SocketOutput = _rawSocketOutput;
139+
}
131140

132141
_frame = CreateFrame();
133142
_frame.Start();

test/Microsoft.AspNet.Server.KestrelTests/EngineTests.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Linq;
65
using System.IO;
6+
using System.Linq;
77
using System.Net;
88
using System.Net.Sockets;
99
using System.Text;
@@ -13,7 +13,7 @@
1313
using Microsoft.AspNet.Http.Features;
1414
using Microsoft.AspNet.Server.Kestrel;
1515
using Microsoft.AspNet.Server.Kestrel.Filter;
16-
using Microsoft.AspNet.Server.Kestrel.Http;
16+
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
1717
using Microsoft.AspNet.Testing.xunit;
1818
using Microsoft.Extensions.Logging;
1919
using Xunit;
@@ -37,7 +37,7 @@ public static TheoryData<ServiceContext> ConnectionFilterData
3737
{
3838
new TestServiceContext
3939
{
40-
ConnectionFilter = new NoOpConnectionFilter()
40+
ConnectionFilter = new PassThroughConnectionFilter()
4141
}
4242
}
4343
};
@@ -1177,5 +1177,14 @@ public void Log(LogLevel logLevel, int eventId, object state, Exception exceptio
11771177
}
11781178
}
11791179
}
1180+
1181+
private class PassThroughConnectionFilter : IConnectionFilter
1182+
{
1183+
public Task OnConnectionAsync(ConnectionFilterContext context)
1184+
{
1185+
context.Connection = new LoggingStream(context.Connection, new TestApplicationErrorLogger());
1186+
return TaskUtilities.CompletedTask;
1187+
}
1188+
}
11801189
}
11811190
}

0 commit comments

Comments
 (0)