From 8b506cf36c85197a9b5bec4cf11d91be31ca06ae Mon Sep 17 00:00:00 2001 From: John Luo Date: Sat, 20 May 2017 11:58:55 -0700 Subject: [PATCH] Cross-compile Response Compression - GZipStream is not flushable on .NET Framework --- .../HttpOverridesSample/HttpOverridesSample.csproj | 4 ++++ .../ResponseBufferingSample.csproj | 4 ++++ .../ResponseCompressionSample.csproj | 4 ++++ samples/RewriteSample/RewriteSample.csproj | 4 ++++ .../GzipCompressionProvider.cs | 6 ++++++ ...Microsoft.AspNetCore.ResponseCompression.csproj | 2 +- .../ResponseCompressionMiddlewareTest.cs | 14 ++++++++++++++ 7 files changed, 37 insertions(+), 1 deletion(-) diff --git a/samples/HttpOverridesSample/HttpOverridesSample.csproj b/samples/HttpOverridesSample/HttpOverridesSample.csproj index 9c8dc46..5caa62c 100644 --- a/samples/HttpOverridesSample/HttpOverridesSample.csproj +++ b/samples/HttpOverridesSample/HttpOverridesSample.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/samples/ResponseBufferingSample/ResponseBufferingSample.csproj b/samples/ResponseBufferingSample/ResponseBufferingSample.csproj index f0aa4a4..1678ae4 100644 --- a/samples/ResponseBufferingSample/ResponseBufferingSample.csproj +++ b/samples/ResponseBufferingSample/ResponseBufferingSample.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/samples/ResponseCompressionSample/ResponseCompressionSample.csproj b/samples/ResponseCompressionSample/ResponseCompressionSample.csproj index a5792ad..9f5ab99 100644 --- a/samples/ResponseCompressionSample/ResponseCompressionSample.csproj +++ b/samples/ResponseCompressionSample/ResponseCompressionSample.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/samples/RewriteSample/RewriteSample.csproj b/samples/RewriteSample/RewriteSample.csproj index f9c78e7..416d269 100644 --- a/samples/RewriteSample/RewriteSample.csproj +++ b/samples/RewriteSample/RewriteSample.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/src/Microsoft.AspNetCore.ResponseCompression/GzipCompressionProvider.cs b/src/Microsoft.AspNetCore.ResponseCompression/GzipCompressionProvider.cs index b7716f1..e825b37 100644 --- a/src/Microsoft.AspNetCore.ResponseCompression/GzipCompressionProvider.cs +++ b/src/Microsoft.AspNetCore.ResponseCompression/GzipCompressionProvider.cs @@ -37,7 +37,13 @@ namespace Microsoft.AspNetCore.ResponseCompression { get { +#if NET461 + return false; +#elif NETSTANDARD2_0 return true; +#else +#error target frameworks need to be updated +#endif } } diff --git a/src/Microsoft.AspNetCore.ResponseCompression/Microsoft.AspNetCore.ResponseCompression.csproj b/src/Microsoft.AspNetCore.ResponseCompression/Microsoft.AspNetCore.ResponseCompression.csproj index d87066a..261c6cc 100644 --- a/src/Microsoft.AspNetCore.ResponseCompression/Microsoft.AspNetCore.ResponseCompression.csproj +++ b/src/Microsoft.AspNetCore.ResponseCompression/Microsoft.AspNetCore.ResponseCompression.csproj @@ -5,7 +5,7 @@ 2.0.0 ASP.NET Core middleware for HTTP Response compression. - netstandard2.0 + net461;netstandard2.0 true aspnetcore diff --git a/test/Microsoft.AspNetCore.ResponseCompression.Tests/ResponseCompressionMiddlewareTest.cs b/test/Microsoft.AspNetCore.ResponseCompression.Tests/ResponseCompressionMiddlewareTest.cs index 7b77fea..fd9a989 100644 --- a/test/Microsoft.AspNetCore.ResponseCompression.Tests/ResponseCompressionMiddlewareTest.cs +++ b/test/Microsoft.AspNetCore.ResponseCompression.Tests/ResponseCompressionMiddlewareTest.cs @@ -505,9 +505,16 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); +#if NET461 // Flush not supported, compression disabled + Assert.NotNull(response.Content.Headers.GetValues(HeaderNames.ContentMD5)); + Assert.Empty(response.Content.Headers.ContentEncoding); +#elif NETCOREAPP2_0 // Flush supported, compression enabled IEnumerable contentMD5 = null; Assert.False(response.Content.Headers.TryGetValues(HeaderNames.ContentMD5, out contentMD5)); Assert.Single(response.Content.Headers.ContentEncoding, "gzip"); +#else +#error Target frameworks need to be updated. +#endif var body = await response.Content.ReadAsStreamAsync(); @@ -563,9 +570,16 @@ namespace Microsoft.AspNetCore.ResponseCompression.Tests var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); +#if NET461 // Flush not supported, compression disabled + Assert.NotNull(response.Content.Headers.GetValues(HeaderNames.ContentMD5)); + Assert.Empty(response.Content.Headers.ContentEncoding); +#elif NETCOREAPP2_0 // Flush supported, compression enabled IEnumerable contentMD5 = null; Assert.False(response.Content.Headers.TryGetValues(HeaderNames.ContentMD5, out contentMD5)); Assert.Single(response.Content.Headers.ContentEncoding, "gzip"); +#else +#error Target framework needs to be updated +#endif var body = await response.Content.ReadAsStreamAsync();