Expose connection features to HTTP/2 connections.

This commit is contained in:
Cesar Blum Silveira 2017-09-18 14:14:31 -07:00 committed by Cesar Blum Silveira
parent 91eb4cd54c
commit c8f9364e3e
3 changed files with 24 additions and 11 deletions

View File

@ -8,6 +8,7 @@ using System.IO.Pipelines;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Protocols; using Microsoft.AspNetCore.Protocols;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.HPack;
@ -50,6 +51,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
public IKestrelTrace Log => _context.ServiceContext.Log; public IKestrelTrace Log => _context.ServiceContext.Log;
public IFeatureCollection ConnectionFeatures => _context.ConnectionFeatures;
public void Abort(Exception ex) public void Abort(Exception ex)
{ {
_stopping = true; _stopping = true;
@ -266,6 +269,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
ConnectionId = ConnectionId, ConnectionId = ConnectionId,
StreamId = _incomingFrame.StreamId, StreamId = _incomingFrame.StreamId,
ServiceContext = _context.ServiceContext, ServiceContext = _context.ServiceContext,
ConnectionFeatures = _context.ConnectionFeatures,
PipeFactory = _context.PipeFactory, PipeFactory = _context.PipeFactory,
LocalEndPoint = _context.LocalEndPoint, LocalEndPoint = _context.LocalEndPoint,
RemoteEndPoint = _context.RemoteEndPoint, RemoteEndPoint = _context.RemoteEndPoint,

View File

@ -3,6 +3,7 @@
using System.IO.Pipelines; using System.IO.Pipelines;
using System.Net; using System.Net;
using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
@ -10,6 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
{ {
public string ConnectionId { get; set; } public string ConnectionId { get; set; }
public ServiceContext ServiceContext { get; set; } public ServiceContext ServiceContext { get; set; }
public IFeatureCollection ConnectionFeatures { get; set; }
public PipeFactory PipeFactory { get; set; } public PipeFactory PipeFactory { get; set; }
public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint LocalEndPoint { get; set; }
public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint RemoteEndPoint { get; set; }

View File

@ -115,19 +115,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
// _http1Connection must be initialized before adding the connection to the connection manager // _http1Connection must be initialized before adding the connection to the connection manager
CreateHttp1Connection(httpApplication, transport, application); CreateHttp1Connection(httpApplication, transport, application);
// _http2Connection must be initialized before yield control to the transport thread, // _http2Connection must be initialized before yielding control to the transport thread,
// to prevent a race condition where _http2Connection.Abort() is called just as // to prevent a race condition where _http2Connection.Abort() is called just as
// _http2Connection is about to be initialized. // _http2Connection is about to be initialized.
_http2Connection = new Http2Connection(new Http2ConnectionContext CreateHttp2Connection(httpApplication, transport, application);
{
ConnectionId = _context.ConnectionId,
ServiceContext = _context.ServiceContext,
PipeFactory = PipeFactory,
LocalEndPoint = LocalEndPoint,
RemoteEndPoint = RemoteEndPoint,
Application = application,
Transport = transport
});
// Do this before the first await so we don't yield control to the transport until we've // Do this before the first await so we don't yield control to the transport until we've
// added the connection to the connection manager // added the connection to the connection manager
@ -135,6 +126,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
_lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks; _lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks;
_http1Connection.ConnectionFeatures.Set<IConnectionTimeoutFeature>(this); _http1Connection.ConnectionFeatures.Set<IConnectionTimeoutFeature>(this);
_http2Connection.ConnectionFeatures.Set<IConnectionTimeoutFeature>(this);
if (adaptedPipeline != null) if (adaptedPipeline != null)
{ {
@ -190,6 +182,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
}); });
} }
internal void CreateHttp2Connection<TContext>(IHttpApplication<TContext> httpApplication, IPipeConnection transport, IPipeConnection application)
{
_http2Connection = new Http2Connection(new Http2ConnectionContext
{
ConnectionId = _context.ConnectionId,
ServiceContext = _context.ServiceContext,
ConnectionFeatures = _context.ConnectionFeatures,
PipeFactory = PipeFactory,
LocalEndPoint = LocalEndPoint,
RemoteEndPoint = RemoteEndPoint,
Application = application,
Transport = transport
});
}
public void OnConnectionClosed(Exception ex) public void OnConnectionClosed(Exception ex)
{ {
Abort(ex); Abort(ex);