Cross-compile Response Compression

- GZipStream is not flushable on .NET Framework
This commit is contained in:
John Luo 2017-05-20 11:58:55 -07:00
Родитель 565b94e3af
Коммит 8b506cf36c
7 изменённых файлов: 37 добавлений и 1 удалений

Просмотреть файл

@ -15,4 +15,8 @@
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(AspNetCoreVersion)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
</ItemGroup>
</Project>

Просмотреть файл

@ -15,4 +15,8 @@
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(AspNetCoreVersion)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
</ItemGroup>
</Project>

Просмотреть файл

@ -20,4 +20,8 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
</ItemGroup>
</Project>

Просмотреть файл

@ -16,4 +16,8 @@
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="$(AspNetCoreVersion)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NETStandardLibraryNETFrameworkVersion)" />
</ItemGroup>
</Project>

Просмотреть файл

@ -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
}
}

Просмотреть файл

@ -5,7 +5,7 @@
<PropertyGroup>
<VersionPrefix>2.0.0</VersionPrefix>
<Description>ASP.NET Core middleware for HTTP Response compression.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore</PackageTags>
</PropertyGroup>

Просмотреть файл

@ -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<string> 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<string> 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();