Change context relationships from inheritance to composition.

This commit is contained in:
Cesar Blum Silveira 2016-09-05 20:41:43 -07:00
parent 78c859d7ea
commit 375e8b7022
13 changed files with 363 additions and 158 deletions

View File

@ -66,7 +66,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
_frame = FrameFactory(this); _frame = FrameFactory(this);
_lastTimestamp = Thread.Loop.Now(); _lastTimestamp = Thread.Loop.Now();
} }
@ -75,6 +74,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
} }
public KestrelServerOptions ServerOptions => ListenerContext.ServiceContext.ServerOptions;
private Func<ConnectionContext, Frame> FrameFactory => ListenerContext.ServiceContext.FrameFactory;
private IKestrelTrace Log => ListenerContext.ServiceContext.Log;
private IThreadPool ThreadPool => ListenerContext.ServiceContext.ThreadPool;
private ServerAddress ServerAddress => ListenerContext.ServerAddress;
private KestrelThread Thread => ListenerContext.Thread;
public void Start() public void Start()
{ {
Log.ConnectionStart(ConnectionId); Log.ConnectionStart(ConnectionId);

View File

@ -7,26 +7,18 @@ using Microsoft.AspNetCore.Http.Features;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
public class ConnectionContext : ListenerContext public class ConnectionContext
{ {
public ConnectionContext() public ConnectionContext()
{ {
} }
public ConnectionContext(ListenerContext context) : base(context) public ConnectionContext(ListenerContext context)
{ {
ListenerContext = context;
} }
public ConnectionContext(ConnectionContext context) : base(context) public ListenerContext ListenerContext { get; set; }
{
SocketInput = context.SocketInput;
SocketOutput = context.SocketOutput;
ConnectionControl = context.ConnectionControl;
RemoteEndPoint = context.RemoteEndPoint;
LocalEndPoint = context.LocalEndPoint;
ConnectionId = context.ConnectionId;
PrepareRequest = context.PrepareRequest;
}
public SocketInput SocketInput { get; set; } public SocketInput SocketInput { get; set; }

View File

@ -11,6 +11,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.Extensions.Internal; using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -20,7 +21,7 @@ using Microsoft.Extensions.Primitives;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
public abstract partial class Frame : ConnectionContext, IFrameControl public abstract partial class Frame : IFrameControl
{ {
private static readonly ArraySegment<byte> _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); private static readonly ArraySegment<byte> _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n");
private static readonly ArraySegment<byte> _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n"); private static readonly ArraySegment<byte> _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n");
@ -72,14 +73,45 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
protected readonly long _keepAliveMilliseconds; protected readonly long _keepAliveMilliseconds;
public Frame(ConnectionContext context) public Frame(ConnectionContext context)
: base(context)
{ {
_pathBase = context.ServerAddress.PathBase; ConnectionContext = context;
SocketInput = context.SocketInput;
SocketOutput = context.SocketOutput;
ServerOptions = context.ListenerContext.ServiceContext.ServerOptions;
_pathBase = ServerAddress.PathBase;
FrameControl = this; FrameControl = this;
_keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds; _keepAliveMilliseconds = (long)ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds;
} }
public ConnectionContext ConnectionContext { get; }
public SocketInput SocketInput { get; set; }
public ISocketOutput SocketOutput { get; set; }
public Action<IFeatureCollection> PrepareRequest
{
get
{
return ConnectionContext.PrepareRequest;
}
set
{
ConnectionContext.PrepareRequest = value;
}
}
protected IConnectionControl ConnectionControl => ConnectionContext.ConnectionControl;
protected IKestrelTrace Log => ConnectionContext.ListenerContext.ServiceContext.Log;
private DateHeaderValueManager DateHeaderValueManager => ConnectionContext.ListenerContext.ServiceContext.DateHeaderValueManager;
private ServerAddress ServerAddress => ConnectionContext.ListenerContext.ServerAddress;
// Hold direct reference to ServerOptions since this is used very often in the request processing path
private KestrelServerOptions ServerOptions { get; }
private IPEndPoint LocalEndPoint => ConnectionContext.LocalEndPoint;
private IPEndPoint RemoteEndPoint => ConnectionContext.RemoteEndPoint;
private string ConnectionId => ConnectionContext.ConnectionId;
public string ConnectionIdFeature { get; set; } public string ConnectionIdFeature { get; set; }
public IPAddress RemoteIpAddress { get; set; } public IPAddress RemoteIpAddress { get; set; }
public int RemotePort { get; set; } public int RemotePort { get; set; }
@ -736,7 +768,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
responseHeaders.SetRawContentLength("0", _bytesContentLengthZero); responseHeaders.SetRawContentLength("0", _bytesContentLengthZero);
} }
} }
else if(_keepAlive) else if (_keepAlive)
{ {
// Note for future reference: never change this to set _autoChunk to true on HTTP/1.0 // Note for future reference: never change this to set _autoChunk to true on HTTP/1.0
// connections, even if we were to infer the client supports it because an HTTP/1.0 request // connections, even if we were to infer the client supports it because an HTTP/1.0 request

View File

@ -23,6 +23,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
protected UvStreamHandle ListenSocket { get; private set; } protected UvStreamHandle ListenSocket { get; private set; }
public IKestrelTrace Log => ServiceContext.Log;
public Task StartAsync( public Task StartAsync(
ServerAddress address, ServerAddress address,
KestrelThread thread) KestrelThread thread)

View File

@ -1,32 +1,21 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
public class ListenerContext : ServiceContext public class ListenerContext
{ {
public ListenerContext() public ListenerContext(ServiceContext serviceContext)
{ {
ServiceContext = serviceContext;
} }
public ListenerContext(ServiceContext serviceContext) public ServiceContext ServiceContext { get; set; }
: base(serviceContext)
{
}
public ListenerContext(ListenerContext listenerContext)
: base(listenerContext)
{
ServerAddress = listenerContext.ServerAddress;
Thread = listenerContext.Thread;
}
public ServerAddress ServerAddress { get; set; } public ServerAddress ServerAddress { get; set; }
public KestrelThread Thread { get; set; } public KestrelThread Thread { get; set; }
public KestrelServerOptions ServerOptions => ServiceContext.ServerOptions;
} }
} }

View File

@ -12,7 +12,7 @@ using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
/// <summary> /// <summary>
/// A secondary listener is delegated requests from a primary listener via a named pipe or /// A secondary listener is delegated requests from a primary listener via a named pipe or
/// UNIX domain socket. /// UNIX domain socket.
/// </summary> /// </summary>
public abstract class ListenerSecondary : ListenerContext, IAsyncDisposable public abstract class ListenerSecondary : ListenerContext, IAsyncDisposable
@ -29,6 +29,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
UvPipeHandle DispatchPipe { get; set; } UvPipeHandle DispatchPipe { get; set; }
public IKestrelTrace Log => ServiceContext.Log;
public Task StartAsync( public Task StartAsync(
string pipeName, string pipeName,
ServerAddress address, ServerAddress address,

View File

@ -5,13 +5,15 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking; using Microsoft.AspNetCore.Server.Kestrel.Internal.Networking;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal namespace Microsoft.AspNetCore.Server.Kestrel.Internal
{ {
public class KestrelEngine : ServiceContext, IDisposable public class KestrelEngine : IDisposable
{ {
public KestrelEngine(ServiceContext context) public KestrelEngine(ServiceContext context)
: this(new Libuv(), context) : this(new Libuv(), context)
@ -19,15 +21,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
// For testing // For testing
internal KestrelEngine(Libuv uv, ServiceContext context) internal KestrelEngine(Libuv uv, ServiceContext context)
: base(context)
{ {
Libuv = uv; Libuv = uv;
ServiceContext = context;
Threads = new List<KestrelThread>(); Threads = new List<KestrelThread>();
} }
public Libuv Libuv { get; private set; } public Libuv Libuv { get; private set; }
public ServiceContext ServiceContext { get; set; }
public List<KestrelThread> Threads { get; private set; } public List<KestrelThread> Threads { get; private set; }
public IApplicationLifetime AppLifetime => ServiceContext.AppLifetime;
public IKestrelTrace Log => ServiceContext.Log;
public IThreadPool ThreadPool => ServiceContext.ThreadPool;
public KestrelServerOptions ServerOptions => ServiceContext.ServerOptions;
public void Start(int count) public void Start(int count)
{ {
for (var index = 0; index < count; index++) for (var index = 0; index < count; index++)
@ -71,16 +79,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
if (single) if (single)
{ {
var listener = usingPipes ? var listener = usingPipes ?
(Listener) new PipeListener(this) : (Listener) new PipeListener(ServiceContext) :
new TcpListener(this); new TcpListener(ServiceContext);
listeners.Add(listener); listeners.Add(listener);
listener.StartAsync(address, thread).Wait(); listener.StartAsync(address, thread).Wait();
} }
else if (first) else if (first)
{ {
var listener = usingPipes var listener = usingPipes
? (ListenerPrimary) new PipeListenerPrimary(this) ? (ListenerPrimary) new PipeListenerPrimary(ServiceContext)
: new TcpListenerPrimary(this); : new TcpListenerPrimary(ServiceContext);
listeners.Add(listener); listeners.Add(listener);
listener.StartAsync(pipeName, address, thread).Wait(); listener.StartAsync(pipeName, address, thread).Wait();
@ -88,8 +96,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
else else
{ {
var listener = usingPipes var listener = usingPipes
? (ListenerSecondary) new PipeListenerSecondary(this) ? (ListenerSecondary) new PipeListenerSecondary(ServiceContext)
: new TcpListenerSecondary(this); : new TcpListenerSecondary(ServiceContext);
listeners.Add(listener); listeners.Add(listener);
listener.StartAsync(pipeName, address, thread).Wait(); listener.StartAsync(pipeName, address, thread).Wait();
} }

View File

@ -10,20 +10,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal
{ {
public class ServiceContext public class ServiceContext
{ {
public ServiceContext()
{
}
public ServiceContext(ServiceContext context)
{
AppLifetime = context.AppLifetime;
Log = context.Log;
ThreadPool = context.ThreadPool;
FrameFactory = context.FrameFactory;
DateHeaderValueManager = context.DateHeaderValueManager;
ServerOptions = context.ServerOptions;
}
public IApplicationLifetime AppLifetime { get; set; } public IApplicationLifetime AppLifetime { get; set; }
public IKestrelTrace Log { get; set; } public IKestrelTrace Log { get; set; }

View File

@ -27,10 +27,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
engine.Start(count: 1); engine.Start(count: 1);
var trace = new TestKestrelTrace(); var trace = new TestKestrelTrace();
var context = new ListenerContext(new TestServiceContext()) var serviceContext = new TestServiceContext
{ {
FrameFactory = connectionContext => new Frame<HttpContext>( FrameFactory = connectionContext => new Frame<HttpContext>(
new DummyApplication(httpContext => TaskCache.CompletedTask), connectionContext), new DummyApplication(httpContext => TaskCache.CompletedTask), connectionContext),
};
var context = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"), ServerAddress = ServerAddress.FromUrl("http://127.0.0.1:0"),
Thread = engine.Threads[0] Thread = engine.Threads[0]
}; };

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using Xunit; using Xunit;
@ -18,12 +19,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
var serverOptions = new KestrelServerOptions(); var serverOptions = new KestrelServerOptions();
var connectionContext = new ConnectionContext var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = serverOptions
ServerOptions = serverOptions,
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);

View File

@ -27,12 +27,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(),
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -70,12 +75,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(),
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -112,12 +122,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(),
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -153,12 +168,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -194,13 +215,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -222,13 +248,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -259,13 +290,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -290,13 +326,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -322,13 +363,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -358,13 +404,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -389,13 +440,18 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -422,13 +478,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
var options = new KestrelServerOptions(); var options = new KestrelServerOptions();
options.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1; options.Limits.MaxRequestHeadersTotalSize = headerLine.Length - 1;
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = options, ServerOptions = options,
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -456,13 +516,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
var options = new KestrelServerOptions(); var options = new KestrelServerOptions();
options.Limits.MaxRequestHeaderCount = 1; options.Limits.MaxRequestHeaderCount = 1;
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = options, ServerOptions = options,
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -491,12 +555,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(),
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -519,12 +588,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public void ResetResetsScheme() public void ResetResetsScheme()
{ {
// Arrange // Arrange
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(),
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Scheme = "https"; frame.Scheme = "https";
@ -550,12 +624,16 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
options.Limits.MaxRequestHeadersTotalSize = headerLine1.Length; options.Limits.MaxRequestHeadersTotalSize = headerLine1.Length;
options.Limits.MaxRequestHeaderCount = 1; options.Limits.MaxRequestHeaderCount = 1;
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = options ServerOptions = options
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -583,13 +661,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public void ThrowsWhenStatusCodeIsSetAfterResponseStarted() public void ThrowsWhenStatusCodeIsSetAfterResponseStarted()
{ {
// Arrange // Arrange
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(), };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
SocketOutput = new MockSocketOuptut() SocketOutput = new MockSocketOuptut()
}; };
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -605,13 +690,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public void ThrowsWhenReasonPhraseIsSetAfterResponseStarted() public void ThrowsWhenReasonPhraseIsSetAfterResponseStarted()
{ {
// Arrange // Arrange
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(), };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
SocketOutput = new MockSocketOuptut() SocketOutput = new MockSocketOuptut()
}; };
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -627,13 +719,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public void ThrowsWhenOnStartingIsSetAfterResponseStarted() public void ThrowsWhenOnStartingIsSetAfterResponseStarted()
{ {
// Arrange // Arrange
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(), };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
SocketOutput = new MockSocketOuptut() SocketOutput = new MockSocketOuptut()
}; };
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.InitializeHeaders(); frame.InitializeHeaders();
frame.Write(new ArraySegment<byte>(new byte[1])); frame.Write(new ArraySegment<byte>(new byte[1]));
@ -647,13 +746,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public void InitializeHeadersResetsRequestHeaders() public void InitializeHeadersResetsRequestHeaders()
{ {
// Arrange // Arrange
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(), };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
SocketOutput = new MockSocketOuptut() SocketOutput = new MockSocketOuptut()
}; };
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -671,13 +777,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public void InitializeHeadersResetsResponseHeaders() public void InitializeHeadersResetsResponseHeaders()
{ {
// Arrange // Arrange
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(), };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
SocketOutput = new MockSocketOuptut() SocketOutput = new MockSocketOuptut()
}; };
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -695,13 +808,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public void InitializeStreamsResetsStreams() public void InitializeStreamsResetsStreams()
{ {
// Arrange // Arrange
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ServerOptions = new KestrelServerOptions(), };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
SocketOutput = new MockSocketOuptut() SocketOutput = new MockSocketOuptut()
}; };
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -732,14 +852,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
ConnectionControl = new Mock<IConnectionControl>().Object,
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
};
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = new Mock<IConnectionControl>().Object
};
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -779,14 +905,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
ConnectionControl = new Mock<IConnectionControl>().Object,
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
};
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = new Mock<IConnectionControl>().Object
};
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -806,15 +938,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionControl = new Mock<IConnectionControl>(); var serviceContext = new ServiceContext
var connectionContext = new ConnectionContext()
{ {
ConnectionControl = connectionControl.Object,
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
};
var connectionControl = new Mock<IConnectionControl>();
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = connectionControl.Object
};
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -834,15 +972,21 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionControl = new Mock<IConnectionControl>(); var serviceContext = new ServiceContext
var connectionContext = new ConnectionContext()
{ {
ConnectionControl = connectionControl.Object,
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionControl = new Mock<IConnectionControl>();
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = connectionControl.Object
};
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -859,11 +1003,9 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
ConnectionControl = Mock.Of<IConnectionControl>(),
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions() ServerOptions = new KestrelServerOptions()
{ {
Limits = Limits =
@ -873,6 +1015,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
}, },
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = Mock.Of<IConnectionControl>()
};
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -904,14 +1054,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
ConnectionControl = Mock.Of<IConnectionControl>(),
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = Mock.Of<IConnectionControl>()
};
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -932,14 +1088,20 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
ConnectionControl = Mock.Of<IConnectionControl>(),
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = Mock.Of<IConnectionControl>(),
};
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
@ -960,13 +1122,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -1013,13 +1179,17 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
};
var connectionContext = new ConnectionContext(listenerContext);
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
frame.InitializeHeaders(); frame.InitializeHeaders();
@ -1039,20 +1209,26 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var pool = new MemoryPool()) using (var pool = new MemoryPool())
using (var socketInput = new SocketInput(pool, ltp)) using (var socketInput = new SocketInput(pool, ltp))
{ {
var connectionControl = new Mock<IConnectionControl>(); var serviceContext = new ServiceContext
var connectionContext = new ConnectionContext()
{ {
ConnectionControl = connectionControl.Object,
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"),
ServerOptions = new KestrelServerOptions(), ServerOptions = new KestrelServerOptions(),
Log = trace Log = trace
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionControl = new Mock<IConnectionControl>();
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = connectionControl.Object
};
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.Reset(); frame.Reset();
var requestProcessingTask = frame.RequestProcessingAsync(); var requestProcessingTask = frame.RequestProcessingAsync();
connectionControl.Verify(cc => cc.SetTimeout((long)connectionContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds)); connectionControl.Verify(cc => cc.SetTimeout((long)serviceContext.ServerOptions.Limits.KeepAliveTimeout.TotalMilliseconds));
frame.Stop(); frame.Stop();
socketInput.IncomingFin(); socketInput.IncomingFin();

View File

@ -5,6 +5,7 @@ using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.Kestrel; using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
{ {
ConnectionControl = this; ConnectionControl = this;
RequestAbortedSource = new CancellationTokenSource(); RequestAbortedSource = new CancellationTokenSource();
ServerOptions = options; ListenerContext = new ListenerContext(new ServiceContext { ServerOptions = options });
} }
public override void Abort(Exception error = null) public override void Abort(Exception error = null)

View File

@ -22,19 +22,22 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
var trace = new KestrelTrace(new TestKestrelTrace()); var trace = new KestrelTrace(new TestKestrelTrace());
var ltp = new LoggingThreadPool(trace); var ltp = new LoggingThreadPool(trace);
var connectionContext = new ConnectionContext() var serviceContext = new ServiceContext
{
ServerAddress = new ServerAddress(),
ServerOptions = new KestrelServerOptions()
};
var context = new Frame<object>(null, connectionContext)
{ {
DateHeaderValueManager = new DateHeaderValueManager(), DateHeaderValueManager = new DateHeaderValueManager(),
ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ServerOptions = new KestrelServerOptions()
ConnectionControl = this,
FrameControl = this
}; };
var listenerContext = new ListenerContext(serviceContext)
{
ServerAddress = ServerAddress.FromUrl("http://localhost:5000")
};
var connectionContext = new ConnectionContext(listenerContext)
{
ConnectionControl = this
};
var context = new Frame<object>(null, connectionContext);
FrameContext = context; FrameContext = context;
FrameContext.FrameControl = this;
_memoryPool = new MemoryPool(); _memoryPool = new MemoryPool();
FrameContext.SocketInput = new SocketInput(_memoryPool, ltp); FrameContext.SocketInput = new SocketInput(_memoryPool, ltp);