Convert IServerInformation to IFeatureCollection.
This commit is contained in:
Родитель
195e06970a
Коммит
0603a69b2c
|
@ -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<Microsoft.Net.Http.Server.WebListener>();
|
||||
listener.UrlPrefixes.Add("http://localhost:12346/pathBase/");
|
||||
|
||||
app.Use(async (context, next) =>
|
||||
|
|
|
@ -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<WebListener>();
|
||||
listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.AllowAnonymous;
|
||||
|
||||
loggerfactory.AddConsole(LogLevel.Verbose);
|
||||
|
||||
|
|
|
@ -64,11 +64,14 @@ namespace Microsoft.AspNet.Server.WebListener
|
|||
/// </summary>
|
||||
/// <param name="properties"></param>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -76,27 +79,25 @@ namespace Microsoft.AspNet.Server.WebListener
|
|||
/// <param name="app">The per-request application entry point.</param>
|
||||
/// <param name="server">The value returned </param>
|
||||
/// <returns>The server. Invoke Dispose to shut down.</returns>
|
||||
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<MessagePump>();
|
||||
if (messagePump == null)
|
||||
{
|
||||
throw new ArgumentException("server");
|
||||
throw new InvalidOperationException("messagePump");
|
||||
}
|
||||
|
||||
// TODO: var capabilities = new Dictionary<string, object>();
|
||||
|
||||
serverInfo.MessagePump.Start(app);
|
||||
return serverInfo.MessagePump;
|
||||
messagePump.Start(app);
|
||||
return messagePump;
|
||||
}
|
||||
|
||||
private void ParseAddresses(IConfiguration config, Microsoft.Net.Http.Server.WebListener listener)
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Microsoft.Net.Http.Server.WebListener>();
|
||||
|
||||
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<string> SendRequestAsync(string uri)
|
||||
|
|
|
@ -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<Microsoft.Net.Http.Server.WebListener>();
|
||||
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);
|
||||
|
|
|
@ -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<Microsoft.Net.Http.Server.WebListener>();
|
||||
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<Microsoft.Net.Http.Server.WebListener>().UrlPrefixes.Add(UrlPrefix.Create(scheme, host, port, path));
|
||||
return factory.Start(serverFeatures, app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче