Reacting to new Hosting API

This commit is contained in:
John Luo 2015-12-16 12:34:36 -08:00
parent 717b355bfd
commit bd10d507f8
15 changed files with 133 additions and 117 deletions

View File

@ -1,3 +0,0 @@

Server = Microsoft.AspNet.Server.Kestrel
Server.Urls = http://localhost:5001/

View File

@ -1,9 +1,10 @@
// 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 Microsoft.AspNet.Builder;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
namespace LargeResponseApp namespace LargeResponseApp
{ {
@ -34,5 +35,15 @@ namespace LargeResponseApp
} }
}); });
} }
public static void Main(string[] args)
{
var application = new WebApplicationBuilder()
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
.UseStartup<Startup>()
.Build();
application.Run();
}
} }
} }

View File

@ -0,0 +1,4 @@
{
"server": "Microsoft.AspNet.Server.Kestrel",
"server.urls": "http://localhost:5001/"
}

View File

@ -3,14 +3,14 @@
"dependencies": { "dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*" "Microsoft.AspNet.Server.Kestrel": "1.0.0-*"
}, },
"compilationOptions": {
"emitEntryPoint": true
},
"frameworks": { "frameworks": {
"dnx451": { }, "dnx451": { },
"dnxcore50": { } "dnxcore50": { }
}, },
"commands": { "commands": {
"run": "Microsoft.AspNet.Server.Kestrel", "web": "LargeResponseApp"
"web": "Microsoft.AspNet.Hosting"
} }
} }

View File

@ -1,17 +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.
using System;
using System.Linq;
namespace SampleApp
{
public class Program
{
public static void Main(string[] args)
{
var mergedArgs = new[] { "--server", "Microsoft.AspNet.Server.Kestrel" }.Concat(args).ToArray();
Microsoft.AspNet.Hosting.Program.Main(mergedArgs);
}
}
}

View File

@ -5,6 +5,7 @@ using System;
using System.IO; using System.IO;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using Microsoft.AspNet.Builder; using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Server.Kestrel; using Microsoft.AspNet.Server.Kestrel;
@ -61,5 +62,20 @@ namespace SampleApp
await context.Response.WriteAsync("Hello world"); await context.Response.WriteAsync("Hello world");
}); });
} }
public static void Main(string[] args)
{
var application = new WebApplicationBuilder()
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
.UseStartup<Startup>()
.Build();
// The following section should be used to demo sockets
//var addresses = application.GetAddresses();
//addresses.Clear();
//addresses.Add("http://unix:/tmp/kestrel-test.sock");
application.Run();
}
} }
} }

View File

@ -0,0 +1,4 @@
{
"server": "Microsoft.AspNet.Server.Kestrel",
"server.urls": "http://localhost:5000;https://localhost:5001"
}

View File

@ -1,22 +1,23 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"dependencies": { "dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*", "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*" "Microsoft.Extensions.Logging.Console": "1.0.0-*"
},
"compilationOptions": {
"emitEntryPoint": true
},
"frameworks": {
"dnx451": {
}, },
"frameworks": { "dnxcore50": {
"dnx451": { "dependencies": {
}, "System.Console": "4.0.0-*"
"dnxcore50": { }
"dependencies": {
"System.Console": "4.0.0-*"
}
}
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001",
"kestrel": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000;https://localhost:5001",
"run-socket": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/tmp/kestrel-test.sock"
} }
},
"commands": {
"web": "SampleApp"
}
} }

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" forwardWindowsAuthToken="false" startupTimeLimit="3600" />
</system.webServer>
</configuration>

View File

@ -1,17 +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.
using System;
using System.Linq;
namespace Microsoft.AspNet.Server.Kestrel
{
public class Program
{
public static void Main(string[] args)
{
var mergedArgs = new[] { "--server", "Microsoft.AspNet.Server.Kestrel" }.Concat(args).ToArray();
Microsoft.AspNet.Hosting.Program.Main(mergedArgs);
}
}
}

View File

@ -40,11 +40,12 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config); var applicationBuilder = new WebApplicationBuilder()
hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); .UseConfiguration(config)
hostBuilder.UseStartup(ConfigureEchoAddress); .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.Configure(ConfigureEchoAddress);
using (var app = hostBuilder.Build().Start()) using (var app = applicationBuilder.Build().Start())
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {

View File

@ -79,9 +79,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
{ "server.urls", registerAddress } { "server.urls", registerAddress }
}).Build(); }).Build();
var builder = new WebHostBuilder(config) var builder = new WebApplicationBuilder()
.UseConfiguration(config)
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.UseStartup(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {

View File

@ -29,31 +29,32 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config); var applicationBuilder = new WebApplicationBuilder()
hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); .UseConfiguration(config)
hostBuilder.UseStartup(app => .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
{ .Configure(app =>
app.Run(async context =>
{ {
// Read the full request body app.Run(async context =>
var total = 0;
var bytes = new byte[1024];
var count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length);
while (count > 0)
{ {
for (int i = 0; i < count; i++) // Read the full request body
var total = 0;
var bytes = new byte[1024];
var count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length);
while (count > 0)
{ {
Assert.Equal(total % 256, bytes[i]); for (int i = 0; i < count; i++)
total++; {
Assert.Equal(total % 256, bytes[i]);
total++;
}
count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length);
} }
count = await context.Request.Body.ReadAsync(bytes, 0, bytes.Length);
}
await context.Response.WriteAsync(total.ToString(CultureInfo.InvariantCulture)); await context.Response.WriteAsync(total.ToString(CultureInfo.InvariantCulture));
});
}); });
});
using (var app = hostBuilder.Build().Start()) using (var app = applicationBuilder.Build().Start())
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
@ -97,9 +98,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
{ "server.urls", "http://localhost:8791" } { "server.urls", "http://localhost:8791" }
}).Build(); }).Build();
var builder = new WebHostBuilder(config) var builder = new WebApplicationBuilder()
.UseConfiguration(config)
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.UseStartup(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {
@ -126,9 +128,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
{ "server.urls", $"http://{registerAddress}:{port}" } { "server.urls", $"http://{registerAddress}:{port}" }
}).Build(); }).Build();
var builder = new WebHostBuilder(config) var builder = new WebApplicationBuilder()
.UseConfiguration(config)
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.UseStartup(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {

View File

@ -28,28 +28,29 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config); var applicationBuilder = new WebApplicationBuilder()
hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); .UseConfiguration(config)
hostBuilder.UseStartup(app => .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
{ .Configure(app =>
app.Run(async context =>
{ {
var bytes = new byte[1024]; app.Run(async context =>
for (int i = 0; i < bytes.Length; i++)
{ {
bytes[i] = (byte)i; var bytes = new byte[1024];
} for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = (byte)i;
}
context.Response.ContentLength = bytes.Length * 1024; context.Response.ContentLength = bytes.Length * 1024;
for (int i = 0; i < 1024; i++) for (int i = 0; i < 1024; i++)
{ {
await context.Response.Body.WriteAsync(bytes, 0, bytes.Length); await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
} }
});
}); });
});
using (var app = hostBuilder.Build().Start()) using (var app = applicationBuilder.Build().Start())
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {
@ -85,9 +86,10 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config) var hostBuilder = new WebApplicationBuilder()
.UseConfiguration(config)
.UseServerFactory("Microsoft.AspNet.Server.Kestrel") .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
.UseStartup(app => .Configure(app =>
{ {
app.Run(async context => app.Run(async context =>
{ {

View File

@ -24,19 +24,20 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
}) })
.Build(); .Build();
var hostBuilder = new WebHostBuilder(config); var applicationBuilder = new WebApplicationBuilder()
hostBuilder.UseServerFactory("Microsoft.AspNet.Server.Kestrel"); .UseConfiguration(config)
hostBuilder.UseStartup(app => .UseServerFactory("Microsoft.AspNet.Server.Kestrel")
{ .Configure(app =>
var serverInfo = app.ServerFeatures.Get<IKestrelServerInformation>();
serverInfo.ThreadCount = threadCount;
app.Run(context =>
{ {
return context.Response.WriteAsync("Hello World"); var serverInfo = app.ServerFeatures.Get<IKestrelServerInformation>();
}); serverInfo.ThreadCount = threadCount;
}); app.Run(context =>
{
return context.Response.WriteAsync("Hello World");
});
});
using (var app = hostBuilder.Build().Start()) using (var app = applicationBuilder.Build().Start())
{ {
using (var client = new HttpClient()) using (var client = new HttpClient())
{ {