diff --git a/samples/HotAddSample/Startup.cs b/samples/HotAddSample/Startup.cs index e1424665a4..9064491c5b 100644 --- a/samples/HotAddSample/Startup.cs +++ b/samples/HotAddSample/Startup.cs @@ -1,7 +1,7 @@ using System; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Server.WebListener; +using Microsoft.AspNet.Http.Features; using Microsoft.Framework.Logging; namespace HotAddSample @@ -15,8 +15,7 @@ namespace HotAddSample { loggerfactory.AddConsole(LogLevel.Information); - var server = (ServerInformation)app.Server; - var listener = server.Listener; + var listener = app.ServerFeatures.Get(); listener.UrlPrefixes.Add("http://localhost:12346/pathBase/"); app.Use(async (context, next) => diff --git a/samples/SelfHostServer/Startup.cs b/samples/SelfHostServer/Startup.cs index a2948987dc..f7d41f42e5 100644 --- a/samples/SelfHostServer/Startup.cs +++ b/samples/SelfHostServer/Startup.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Server.WebListener; +using Microsoft.AspNet.Http.Features; using Microsoft.Framework.Logging; using Microsoft.Net.Http.Server; @@ -14,8 +14,8 @@ namespace SelfHostServer { public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory) { - var info = (ServerInformation)app.Server; - info.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.AllowAnonymous; + var listener = app.ServerFeatures.Get(); + listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.AllowAnonymous; loggerfactory.AddConsole(LogLevel.Verbose); diff --git a/src/Microsoft.AspNet.Server.WebListener/ServerFactory.cs b/src/Microsoft.AspNet.Server.WebListener/ServerFactory.cs index 693106a9c9..accaf6372c 100644 --- a/src/Microsoft.AspNet.Server.WebListener/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.WebListener/ServerFactory.cs @@ -64,11 +64,14 @@ namespace Microsoft.AspNet.Server.WebListener /// /// [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Disposed by caller")] - public IServerInformation Initialize(IConfiguration configuration) + public IFeatureCollection Initialize(IConfiguration configuration) { Microsoft.Net.Http.Server.WebListener listener = new Microsoft.Net.Http.Server.WebListener(_loggerFactory); ParseAddresses(configuration, listener); - return new ServerInformation(new MessagePump(listener, _loggerFactory)); + var serverFeatures = new FeatureCollection(); + serverFeatures.Set(listener); + serverFeatures.Set(new MessagePump(listener, _loggerFactory)); + return serverFeatures; } /// @@ -76,27 +79,25 @@ namespace Microsoft.AspNet.Server.WebListener /// The per-request application entry point. /// The value returned /// The server. Invoke Dispose to shut down. - public IDisposable Start(IServerInformation server, AppFunc app) + public IDisposable Start(IFeatureCollection serverFeatures, AppFunc app) { - if (server == null) + if (serverFeatures == null) { - throw new ArgumentNullException("server"); + throw new ArgumentNullException("serverFeatures"); } if (app == null) { throw new ArgumentNullException("app"); } - var serverInfo = server as ServerInformation; - if (serverInfo == null) + var messagePump = serverFeatures.Get(); + if (messagePump == null) { - throw new ArgumentException("server"); + throw new InvalidOperationException("messagePump"); } - // TODO: var capabilities = new Dictionary(); - - serverInfo.MessagePump.Start(app); - return serverInfo.MessagePump; + messagePump.Start(app); + return messagePump; } private void ParseAddresses(IConfiguration config, Microsoft.Net.Http.Server.WebListener listener) diff --git a/src/Microsoft.AspNet.Server.WebListener/ServerInformation.cs b/src/Microsoft.AspNet.Server.WebListener/ServerInformation.cs deleted file mode 100644 index 9c50b466f8..0000000000 --- a/src/Microsoft.AspNet.Server.WebListener/ServerInformation.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Open Technologies, Inc. -// All Rights Reserved -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR -// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING -// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF -// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR -// NON-INFRINGEMENT. -// See the Apache 2 License for the specific language governing -// permissions and limitations under the License. - -using System.Reflection; -using Microsoft.AspNet.Hosting.Server; - -namespace Microsoft.AspNet.Server.WebListener -{ - public class ServerInformation : IServerInformation - { - private MessagePump _messagePump; - - internal ServerInformation(MessagePump messagePump) - { - _messagePump = messagePump; - } - - internal MessagePump MessagePump - { - get { return _messagePump; } - } - - // Microsoft.AspNet.Server.WebListener - public string Name - { - get { return GetType().GetTypeInfo().Assembly.GetName().Name; } - } - - public Microsoft.Net.Http.Server.WebListener Listener - { - get { return _messagePump.Listener; } - } - - public int MaxAccepts - { - get { return _messagePump.MaxAccepts; } - set { _messagePump.MaxAccepts = value; } - } - - public bool EnableResponseCaching - { - get { return _messagePump.EnableResponseCaching; } - set { _messagePump.EnableResponseCaching = value; } - } - } -} diff --git a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/RequestTests.cs index a352b9c4c0..0ebbfb6c00 100644 --- a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/RequestTests.cs @@ -174,14 +174,15 @@ namespace Microsoft.AspNet.Server.WebListener server.Dispose(); var rootUri = new Uri(root); var factory = new ServerFactory(loggerFactory: null); - var serverInfo = (ServerInformation)factory.Initialize(configuration: null); + var serverFeatures = factory.Initialize(configuration: null); + var listener = serverFeatures.Get(); foreach (string path in new[] { "/", "/11", "/2/3", "/2", "/11/2" }) { - serverInfo.Listener.UrlPrefixes.Add(UrlPrefix.Create(rootUri.Scheme, rootUri.Host, rootUri.Port, path)); + listener.UrlPrefixes.Add(UrlPrefix.Create(rootUri.Scheme, rootUri.Host, rootUri.Port, path)); } - return factory.Start(serverInfo, app); + return factory.Start(serverFeatures, app); } private async Task SendRequestAsync(string uri) diff --git a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/ServerTests.cs b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/ServerTests.cs index e3299693f5..b787d5e96f 100644 --- a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/ServerTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/ServerTests.cs @@ -253,17 +253,17 @@ namespace Microsoft.AspNet.Server.WebListener [Fact] public async Task Server_SetQueueLimit_Success() { - // TODO: This is just to get a dynamic port + // This is just to get a dynamic port string address; using (Utilities.CreateHttpServer(out address, env => Task.FromResult(0))) { } var factory = new ServerFactory(loggerFactory: null); - var serverInfo = (ServerInformation)factory.Initialize(configuration: null); - serverInfo.Listener.UrlPrefixes.Add(UrlPrefix.Create(address)); + var serverFeatures = factory.Initialize(configuration: null); + var listener = serverFeatures.Get(); + listener.UrlPrefixes.Add(UrlPrefix.Create(address)); + listener.SetRequestQueueLimit(1001); - serverInfo.Listener.SetRequestQueueLimit(1001); - - using (factory.Start(serverInfo, env => Task.FromResult(0))) + using (factory.Start(serverFeatures, env => Task.FromResult(0))) { string response = await SendRequestAsync(address); Assert.Equal(string.Empty, response); diff --git a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/Utilities.cs b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/Utilities.cs index 5e70a77b50..e838ced3fb 100644 --- a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/Utilities.cs +++ b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/Utilities.cs @@ -17,6 +17,7 @@ using System; using System.Threading.Tasks; +using Microsoft.AspNet.Http.Features; using Microsoft.Net.Http.Server; namespace Microsoft.AspNet.Server.WebListener @@ -61,12 +62,13 @@ namespace Microsoft.AspNet.Server.WebListener root = prefix.Scheme + "://" + prefix.Host + ":" + prefix.Port; baseAddress = prefix.ToString(); - var serverInfo = (ServerInformation)factory.Initialize(configuration: null); - serverInfo.Listener.UrlPrefixes.Add(prefix); - serverInfo.Listener.AuthenticationManager.AuthenticationSchemes = authType; + var serverFeatures = factory.Initialize(configuration: null); + var listener = serverFeatures.Get(); + listener.UrlPrefixes.Add(prefix); + listener.AuthenticationManager.AuthenticationSchemes = authType; try { - return factory.Start(serverInfo, app); + return factory.Start(serverFeatures, app); } catch (WebListenerException) { @@ -85,10 +87,9 @@ namespace Microsoft.AspNet.Server.WebListener internal static IDisposable CreateServer(string scheme, string host, int port, string path, AppFunc app) { var factory = new ServerFactory(loggerFactory: null); - var serverInfo = (ServerInformation)factory.Initialize(configuration: null); - serverInfo.Listener.UrlPrefixes.Add(UrlPrefix.Create(scheme, host, port, path)); - - return factory.Start(serverInfo, app); + var serverFeatures = factory.Initialize(configuration: null); + serverFeatures.Get().UrlPrefixes.Add(UrlPrefix.Create(scheme, host, port, path)); + return factory.Start(serverFeatures, app); } } }