Add compression pass through tests (#1525)
This commit is contained in:
parent
48d40e0e36
commit
55d849a0d0
|
|
@ -1,4 +1,4 @@
|
|||
<Project>
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
</PropertyGroup>
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
<MicrosoftAspNetCoreHttpOverridesPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreHttpOverridesPackageVersion>
|
||||
<MicrosoftAspNetCoreHttpPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreHttpPackageVersion>
|
||||
<MicrosoftAspNetCoreHttpSysSourcesPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreHttpSysSourcesPackageVersion>
|
||||
<MicrosoftAspNetCoreResponseCompressionPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreResponseCompressionPackageVersion>
|
||||
<MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.6.0-preview3-35496</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>
|
||||
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreServerKestrelPackageVersion>
|
||||
<MicrosoftAspNetCoreTestHostPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreTestHostPackageVersion>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
// 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.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Testing.xunit;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||
{
|
||||
[Collection(IISCompressionSiteCollection.Name)]
|
||||
public abstract class CompressionTests : FixtureLoggedTest
|
||||
{
|
||||
private readonly IISTestSiteFixture _fixture;
|
||||
|
||||
[Collection(IISTestSiteCollection.Name)]
|
||||
public class InProc: CompressionTests
|
||||
{
|
||||
public InProc(IISTestSiteFixture fixture) : base(fixture) { }
|
||||
}
|
||||
|
||||
[Collection(OutOfProcessTestSiteCollection.Name)]
|
||||
public class OutOfProcess: CompressionTests
|
||||
{
|
||||
public OutOfProcess(OutOfProcessTestSiteFixture fixture) : base(fixture) { }
|
||||
}
|
||||
|
||||
[Collection(OutOfProcessV1TestSiteCollection.Name)]
|
||||
public class OutOfProcessV1: CompressionTests
|
||||
{
|
||||
public OutOfProcessV1(OutOfProcessV1TestSiteFixture fixture) : base(fixture) { }
|
||||
}
|
||||
|
||||
protected CompressionTests(IISTestSiteFixture fixture) : base(fixture)
|
||||
{
|
||||
_fixture = fixture;
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
public async Task PassesThroughCompression()
|
||||
{
|
||||
var request = new HttpRequestMessage(HttpMethod.Get, "/CompressedData");
|
||||
|
||||
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
|
||||
|
||||
var response = await _fixture.Client.SendAsync(request);
|
||||
Assert.Equal("gzip", response.Content.Headers.ContentEncoding.Single());
|
||||
Assert.Equal(
|
||||
new byte[] {
|
||||
0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x04, 0x0B, 0x63, 0x60, 0xA0, 0x3D, 0x00, 0x00,
|
||||
0xCA, 0xC6, 0x88, 0x99, 0x64, 0x00, 0x00, 0x00 },
|
||||
await response.Content.ReadAsByteArrayAsync());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,11 +13,11 @@ using Xunit;
|
|||
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||
{
|
||||
[Collection(IISCompressionSiteCollection.Name)]
|
||||
public class CompressionTests : FixtureLoggedTest
|
||||
public class CompressionModuleTests : FixtureLoggedTest
|
||||
{
|
||||
private readonly IISCompressionSiteFixture _fixture;
|
||||
|
||||
public CompressionTests(IISCompressionSiteFixture fixture): base(fixture)
|
||||
public CompressionModuleTests(IISCompressionSiteFixture fixture): base(fixture)
|
||||
{
|
||||
_fixture = fixture;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="$(MicrosoftAspNetCoreResponseCompressionPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(MicrosoftAspNetCoreHostingPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="$(MicrosoftAspNetCoreWebUtilitiesPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion)" />
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="$(MicrosoftAspNetCoreResponseCompressionPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="$(MicrosoftAspNetCoreWebUtilitiesPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion)" />
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<Import Project="..\..\..\build\testsite.props" />
|
||||
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="$(MicrosoftAspNetCoreResponseCompressionPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsolePackageVersion)" />
|
||||
<PackageReference Include="System.Net.WebSockets.WebSocketProtocol" Version="$(SystemNetWebSocketsWebSocketProtocolPackageVersion)" />
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Linq;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -15,6 +16,11 @@ namespace TestSite
|
|||
{
|
||||
public partial class Startup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.AddResponseCompression();
|
||||
}
|
||||
|
||||
private async Task HostingEnvironment(HttpContext ctx)
|
||||
{
|
||||
var hostingEnv = ctx.RequestServices.GetService<IHostingEnvironment>();
|
||||
|
|
@ -95,5 +101,17 @@ namespace TestSite
|
|||
context.Response.Headers["Server"] = "MyServer/7.8";
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void CompressedData(IApplicationBuilder builder)
|
||||
{
|
||||
builder.UseResponseCompression();
|
||||
// write random bytes to check that compressed data is passed through
|
||||
builder.Run(
|
||||
async context =>
|
||||
{
|
||||
context.Response.ContentType = "text/html";
|
||||
await context.Response.Body.WriteAsync(new byte[100], 0, 100);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue