From 7ae1941c839882f43ddeafe7a57c5823f8ad074a Mon Sep 17 00:00:00 2001 From: Chris R Date: Wed, 13 May 2015 14:14:01 -0700 Subject: [PATCH] Enable additional WebListener response tests. --- .../ResponseTests.cs | 42 ++++++++++++++++--- .../StartupResponses.cs | 10 +++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/test/ServerComparison.FunctionalTests/ResponseTests.cs b/test/ServerComparison.FunctionalTests/ResponseTests.cs index 1a5a247853..992c16d76a 100644 --- a/test/ServerComparison.FunctionalTests/ResponseTests.cs +++ b/test/ServerComparison.FunctionalTests/ResponseTests.cs @@ -37,9 +37,7 @@ namespace ServerComparison.FunctionalTests [ConditionalTheory] [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] [InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x86, "http://localhost:5071/")] - // https://github.com/aspnet/Helios/issues/148 - // TODO: Chunks anyways [InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5073/")] - // https://github.com/aspnet/WebListener/issues/113 + [InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5073/")] public Task ResponseFormats_Windows_ConnectionClose(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl) { return ResponseFormats(serverType, runtimeFlavor, architecture, applicationBaseUrl, CheckConnectionCloseAsync); @@ -72,8 +70,7 @@ namespace ServerComparison.FunctionalTests [ConditionalTheory] [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] [InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5072/")] - // TODO: Not implemented [InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5073/")] - // https://github.com/aspnet/WebListener/issues/112 + [InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5073/")] public Task ResponseFormats_Windows_ManuallyChunk(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl) { return ResponseFormats(serverType, runtimeFlavor, architecture, applicationBaseUrl, CheckManuallyChunkedAsync); @@ -86,6 +83,22 @@ namespace ServerComparison.FunctionalTests return ResponseFormats(serverType, runtimeFlavor, architecture, applicationBaseUrl, CheckManuallyChunkedAsync); } + [ConditionalTheory] + [OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)] + [InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5076/")] + [InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5077/")] + public Task ResponseFormats_Windows_ManuallyChunkAndClose(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl) + { + return ResponseFormats(serverType, runtimeFlavor, architecture, applicationBaseUrl, CheckManuallyChunkedAndCloseAsync); + } + + [Theory] + [InlineData(ServerType.Kestrel, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, "http://localhost:5078/")] + public Task ResponseFormats_Kestrel_ManuallyChunkAndClose(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl) + { + return ResponseFormats(serverType, runtimeFlavor, architecture, applicationBaseUrl, CheckManuallyChunkedAndCloseAsync); + } + public async Task ResponseFormats(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl, Func scenario) { var logger = new LoggerFactory() @@ -205,6 +218,25 @@ namespace ServerComparison.FunctionalTests } } + private static async Task CheckManuallyChunkedAndCloseAsync(HttpClient client, ILogger logger) + { + var response = await client.GetAsync("manuallychunkedandclose"); + var responseText = await response.Content.ReadAsStringAsync(); + try + { + Assert.Equal("Manually Chunked and Close", responseText); + Assert.True(response.Headers.TransferEncodingChunked, "/manuallychunkedandclose, chunked?"); + Assert.True(response.Headers.ConnectionClose, "/manuallychunkedandclose, closed?"); + Assert.Null(GetContentLength(response)); + } + catch (XunitException) + { + logger.LogWarning(response.ToString()); + logger.LogWarning(responseText); + throw; + } + } + private static string GetContentLength(HttpResponseMessage response) { // Don't use response.Content.Headers.ContentLength, it will dynamically calculate the value if it can. diff --git a/test/ServerComparison.TestSites/StartupResponses.cs b/test/ServerComparison.TestSites/StartupResponses.cs index 67fc0800ab..a71c3968f6 100644 --- a/test/ServerComparison.TestSites/StartupResponses.cs +++ b/test/ServerComparison.TestSites/StartupResponses.cs @@ -51,6 +51,16 @@ namespace ServerComparison.TestSites }); }); + app.Map("/manuallychunkedandclose", subApp => + { + subApp.Run(context => + { + context.Response.Headers[HeaderNames.Connection] = "close"; + context.Response.Headers[HeaderNames.TransferEncoding] = "chunked"; + return context.Response.WriteAsync("1A\r\nManually Chunked and Close\r\n0\r\n\r\n"); + }); + }); + app.Run(context => { return context.Response.WriteAsync("Running");