Skip to content

Commit 55d849a

Browse files
authored
Add compression pass through tests (#1525)
1 parent 48d40e0 commit 55d849a

File tree

7 files changed

+84
-4
lines changed

7 files changed

+84
-4
lines changed

build/dependencies.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project>
1+
<Project>
22
<PropertyGroup>
33
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
44
</PropertyGroup>
@@ -15,6 +15,7 @@
1515
<MicrosoftAspNetCoreHttpOverridesPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreHttpOverridesPackageVersion>
1616
<MicrosoftAspNetCoreHttpPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreHttpPackageVersion>
1717
<MicrosoftAspNetCoreHttpSysSourcesPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreHttpSysSourcesPackageVersion>
18+
<MicrosoftAspNetCoreResponseCompressionPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreResponseCompressionPackageVersion>
1819
<MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.6.0-preview3-35496</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>
1920
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreServerKestrelPackageVersion>
2021
<MicrosoftAspNetCoreTestHostPackageVersion>2.2.0-preview3-35496</MicrosoftAspNetCoreTestHostPackageVersion>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Linq;
5+
using System.Net.Http;
6+
using System.Net.Http.Headers;
7+
using System.Threading.Tasks;
8+
using Microsoft.AspNetCore.Testing.xunit;
9+
using Xunit;
10+
11+
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
12+
{
13+
[Collection(IISCompressionSiteCollection.Name)]
14+
public abstract class CompressionTests : FixtureLoggedTest
15+
{
16+
private readonly IISTestSiteFixture _fixture;
17+
18+
[Collection(IISTestSiteCollection.Name)]
19+
public class InProc: CompressionTests
20+
{
21+
public InProc(IISTestSiteFixture fixture) : base(fixture) { }
22+
}
23+
24+
[Collection(OutOfProcessTestSiteCollection.Name)]
25+
public class OutOfProcess: CompressionTests
26+
{
27+
public OutOfProcess(OutOfProcessTestSiteFixture fixture) : base(fixture) { }
28+
}
29+
30+
[Collection(OutOfProcessV1TestSiteCollection.Name)]
31+
public class OutOfProcessV1: CompressionTests
32+
{
33+
public OutOfProcessV1(OutOfProcessV1TestSiteFixture fixture) : base(fixture) { }
34+
}
35+
36+
protected CompressionTests(IISTestSiteFixture fixture) : base(fixture)
37+
{
38+
_fixture = fixture;
39+
}
40+
41+
[ConditionalFact]
42+
public async Task PassesThroughCompression()
43+
{
44+
var request = new HttpRequestMessage(HttpMethod.Get, "/CompressedData");
45+
46+
request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
47+
48+
var response = await _fixture.Client.SendAsync(request);
49+
Assert.Equal("gzip", response.Content.Headers.ContentEncoding.Single());
50+
Assert.Equal(
51+
new byte[] {
52+
0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
53+
0x04, 0x0B, 0x63, 0x60, 0xA0, 0x3D, 0x00, 0x00,
54+
0xCA, 0xC6, 0x88, 0x99, 0x64, 0x00, 0x00, 0x00 },
55+
await response.Content.ReadAsByteArrayAsync());
56+
}
57+
}
58+
}

test/Common.FunctionalTests/Inprocess/CompressionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
1414
{
1515
[Collection(IISCompressionSiteCollection.Name)]
16-
public class CompressionTests : FixtureLoggedTest
16+
public class CompressionModuleTests : FixtureLoggedTest
1717
{
1818
private readonly IISCompressionSiteFixture _fixture;
1919

20-
public CompressionTests(IISCompressionSiteFixture fixture): base(fixture)
20+
public CompressionModuleTests(IISCompressionSiteFixture fixture): base(fixture)
2121
{
2222
_fixture = fixture;
2323
}

test/WebSites/InProcessWebSite/InProcessWebSite.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</ItemGroup>
2121

2222
<ItemGroup>
23+
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="$(MicrosoftAspNetCoreResponseCompressionPackageVersion)" />
2324
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(MicrosoftAspNetCoreHostingPackageVersion)" />
2425
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="$(MicrosoftAspNetCoreWebUtilitiesPackageVersion)" />
2526
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion)" />

test/WebSites/OutOfProcessWebSite/OutOfProcessWebSite.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22+
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="$(MicrosoftAspNetCoreResponseCompressionPackageVersion)" />
2223
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
2324
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="$(MicrosoftAspNetCoreWebUtilitiesPackageVersion)" />
2425
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion)" />

test/WebSites/StressTestWebSite/StressTestWebSite.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<Import Project="..\..\..\build\testsite.props" />
44

@@ -16,6 +16,7 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19+
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="$(MicrosoftAspNetCoreResponseCompressionPackageVersion)" />
1920
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
2021
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsolePackageVersion)" />
2122
<PackageReference Include="System.Net.WebSockets.WebSocketProtocol" Version="$(SystemNetWebSocketsWebSocketProtocolPackageVersion)" />

test/WebSites/shared/SharedStartup/Startup.shared.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using Microsoft.AspNetCore.Authentication;
10+
using Microsoft.AspNetCore.Builder;
1011
using Microsoft.AspNetCore.Hosting;
1112
using Microsoft.AspNetCore.Http;
1213
using Microsoft.Extensions.DependencyInjection;
@@ -15,6 +16,11 @@ namespace TestSite
1516
{
1617
public partial class Startup
1718
{
19+
public void ConfigureServices(IServiceCollection serviceCollection)
20+
{
21+
serviceCollection.AddResponseCompression();
22+
}
23+
1824
private async Task HostingEnvironment(HttpContext ctx)
1925
{
2026
var hostingEnv = ctx.RequestServices.GetService<IHostingEnvironment>();
@@ -95,5 +101,17 @@ public Task OverrideServer(HttpContext context)
95101
context.Response.Headers["Server"] = "MyServer/7.8";
96102
return Task.CompletedTask;
97103
}
104+
105+
public void CompressedData(IApplicationBuilder builder)
106+
{
107+
builder.UseResponseCompression();
108+
// write random bytes to check that compressed data is passed through
109+
builder.Run(
110+
async context =>
111+
{
112+
context.Response.ContentType = "text/html";
113+
await context.Response.Body.WriteAsync(new byte[100], 0, 100);
114+
});
115+
}
98116
}
99117
}

0 commit comments

Comments
 (0)