From e8647c0cb4e1b66ab15c997c1a997fc4df93bef2 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 19 May 2016 02:16:09 +0100 Subject: [PATCH] Remove extra FrameContext class Resolves #837 --- .../Http/Frame.FeatureCollection.cs | 1 + .../Http/Frame.cs | 2 +- .../Http/FrameContext.cs | 18 ------------------ .../Http/FrameResponseStream.cs | 16 ++++++++-------- .../Infrastructure/HttpComponentFactory.cs | 8 ++++---- .../Infrastructure/IHttpComponentFactory.cs | 2 +- .../TestInput.cs | 4 ++-- 7 files changed, 17 insertions(+), 34 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs index 827398ba0c..4e44236545 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.FeatureCollection.cs @@ -73,6 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http MaybeExtra.Add(new KeyValuePair(key, value)); } + public IFrameControl FrameControl { get; set; } string IHttpRequestFeature.Protocol { diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs index c117709f36..fe4b11fccf 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs @@ -20,7 +20,7 @@ using Microsoft.Extensions.Primitives; namespace Microsoft.AspNetCore.Server.Kestrel.Http { - public abstract partial class Frame : FrameContext, IFrameControl + public abstract partial class Frame : ConnectionContext, IFrameControl { private static readonly Encoding _ascii = Encoding.ASCII; private static readonly ArraySegment _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n"); diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs deleted file mode 100644 index e4db400124..0000000000 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameContext.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -namespace Microsoft.AspNetCore.Server.Kestrel.Http -{ - public class FrameContext : ConnectionContext - { - public FrameContext() - { - } - - public FrameContext(ConnectionContext context) : base(context) - { - } - - public IFrameControl FrameControl { get; set; } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs index c7568bed36..522e805e10 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameResponseStream.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { class FrameResponseStream : Stream { - private FrameContext _context; + private IFrameControl _frameControl; private FrameStreamState _state; public FrameResponseStream() @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { ValidateState(default(CancellationToken)); - _context.FrameControl.Flush(); + _frameControl.Flush(); } public override Task FlushAsync(CancellationToken cancellationToken) @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var task = ValidateState(cancellationToken); if (task == null) { - return _context.FrameControl.FlushAsync(cancellationToken); + return _frameControl.FlushAsync(cancellationToken); } return task; } @@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http { ValidateState(default(CancellationToken)); - _context.FrameControl.Write(new ArraySegment(buffer, offset, count)); + _frameControl.Write(new ArraySegment(buffer, offset, count)); } public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) @@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http var task = ValidateState(cancellationToken); if (task == null) { - return _context.FrameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); + return _frameControl.WriteAsync(new ArraySegment(buffer, offset, count), cancellationToken); } return task; } @@ -134,14 +134,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http } } - public void Initialize(FrameContext context) + public void Initialize(IFrameControl frameControl) { - _context = context; + _frameControl = frameControl; } public void Uninitialize() { - _context = null; + _frameControl = null; _state = FrameStreamState.Closed; } diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs index 2669471cd9..4d647e2caa 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/HttpComponentFactory.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure ServerOptions = serverOptions; } - public Streams CreateStreams(FrameContext owner) + public Streams CreateStreams(IFrameControl frameControl) { Streams streams; @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure streams = new Streams(); } - streams.Initialize(owner); + streams.Initialize(frameControl); return streams; } @@ -103,9 +103,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure DuplexStream = new FrameDuplexStream(RequestBody, ResponseBody); } - public void Initialize(FrameContext renter) + public void Initialize(IFrameControl frameControl) { - ResponseBody.Initialize(renter); + ResponseBody.Initialize(frameControl); } public void Uninitialize() diff --git a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs index 926d9cfd26..3dcb234bbd 100644 --- a/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs +++ b/src/Microsoft.AspNetCore.Server.Kestrel/Infrastructure/IHttpComponentFactory.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Infrastructure { KestrelServerOptions ServerOptions { get; set; } - Streams CreateStreams(FrameContext owner); + Streams CreateStreams(IFrameControl frameControl); void DisposeStreams(Streams streams); diff --git a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs index 764e0a521c..d841e180f7 100644 --- a/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs +++ b/test/Microsoft.AspNetCore.Server.KestrelTests/TestInput.cs @@ -18,14 +18,14 @@ namespace Microsoft.AspNetCore.Server.KestrelTests { var trace = new KestrelTrace(new TestKestrelTrace()); var ltp = new LoggingThreadPool(trace); - var context = new FrameContext() + var context = new Frame(null, new ConnectionContext() { ServerAddress = new ServerAddress() }) { DateHeaderValueManager = new DateHeaderValueManager(), ServerAddress = ServerAddress.FromUrl("http://localhost:5000"), ConnectionControl = this, FrameControl = this }; - FrameContext = new Frame(null, context); + FrameContext = context; _memoryPool = new MemoryPool(); FrameContext.SocketInput = new SocketInput(_memoryPool, ltp);