From 5b06a763672a20577ef775334473ae97f1d6e540 Mon Sep 17 00:00:00 2001 From: Stephen Halter Date: Wed, 8 Jul 2015 12:42:32 -0700 Subject: [PATCH] Add sample that can produce large responses --- KestrelHttpServer.sln | 9 ++++- .../LargeResponseApp/LargeResponseApp.xproj | 19 ++++++++++ .../Microsoft.AspNet.Hosting.ini | 3 ++ samples/LargeResponseApp/Startup.cs | 38 +++++++++++++++++++ samples/LargeResponseApp/project.json | 16 ++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 samples/LargeResponseApp/LargeResponseApp.xproj create mode 100644 samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini create mode 100644 samples/LargeResponseApp/Startup.cs create mode 100644 samples/LargeResponseApp/project.json diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index a9437d0659..d2ebe3ed3d 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22111.0 +VisualStudioVersion = 14.0.22823.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kestrel", "src\Microsoft.AspNet.Server.Kestrel\Microsoft.AspNet.Server.Kestrel.xproj", "{F510611A-3BEE-4B88-A613-5F4A74ED82A1}" EndProject @@ -25,6 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D3273454-E EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LargeResponseApp", "samples\LargeResponseApp\LargeResponseApp.xproj", "{B35D4D31-E74C-4646-8A11-7A7A40F0021E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -47,6 +49,10 @@ Global {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Debug|Any CPU.Build.0 = Debug|Any CPU {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.ActiveCfg = Release|Any CPU {30B7617E-58EF-4382-B3EA-5B2E718CF1A6}.Release|Any CPU.Build.0 = Release|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B35D4D31-E74C-4646-8A11-7A7A40F0021E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -56,5 +62,6 @@ Global {37F3BFB2-6454-49E5-9D7F-581BF755CCFE} = {D3273454-EA07-41D2-BF0B-FCC3675C2483} {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {30B7617E-58EF-4382-B3EA-5B2E718CF1A6} = {2D5D5227-4DBD-499A-96B1-76A36B03B750} + {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} EndGlobalSection EndGlobal diff --git a/samples/LargeResponseApp/LargeResponseApp.xproj b/samples/LargeResponseApp/LargeResponseApp.xproj new file mode 100644 index 0000000000..48abc5f22c --- /dev/null +++ b/samples/LargeResponseApp/LargeResponseApp.xproj @@ -0,0 +1,19 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + b35d4d31-e74c-4646-8a11-7a7a40f0021e + LargeResponseApp + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + 2.0 + 42216 + + + \ No newline at end of file diff --git a/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini b/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini new file mode 100644 index 0000000000..3fc5452c97 --- /dev/null +++ b/samples/LargeResponseApp/Microsoft.AspNet.Hosting.ini @@ -0,0 +1,3 @@ + +Server = Kestrel +Server.Urls = http://localhost:5001/ diff --git a/samples/LargeResponseApp/Startup.cs b/samples/LargeResponseApp/Startup.cs new file mode 100644 index 0000000000..407b1fdd49 --- /dev/null +++ b/samples/LargeResponseApp/Startup.cs @@ -0,0 +1,38 @@ +// 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 Microsoft.AspNet.Builder; +using System.Text; +using System.Threading.Tasks; + +namespace LargeResponseApp +{ + public class Startup + { + private const int _chunkSize = 4096; + private const int _defaultNumChunks = 16; + private static byte[] _chunk = Encoding.UTF8.GetBytes(new string('a', _chunkSize)); + private static Task _emptyTask = Task.FromResult(null); + + public void Configure(IApplicationBuilder app) + { + app.Run(async (context) => + { + int numChunks; + var path = context.Request.Path; + if (!path.HasValue || !int.TryParse(path.Value.Substring(1), out numChunks)) + { + numChunks = _defaultNumChunks; + } + + context.Response.ContentLength = _chunkSize * numChunks; + context.Response.ContentType = "text/plain"; + + for (int i = 0; i < numChunks; i++) + { + await context.Response.Body.WriteAsync(_chunk, 0, _chunkSize); + } + }); + } + } +} diff --git a/samples/LargeResponseApp/project.json b/samples/LargeResponseApp/project.json new file mode 100644 index 0000000000..f533e7ed47 --- /dev/null +++ b/samples/LargeResponseApp/project.json @@ -0,0 +1,16 @@ +{ + "version": "1.0.0-*", + "dependencies": { + "Kestrel": "1.0.0-*" + }, + + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + }, + + "commands": { + "run": "Kestrel", + "web": "Microsoft.AspNet.Hosting" + } +}