Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Shared/EmbeddedResourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ public async Task<bool> TryRespondWithFileAsync(HttpContext httpContext)

private static bool IsGZipAccepted(HttpRequest httpRequest)
{
var acceptEncoding = httpRequest.Headers.AcceptEncoding;
if (httpRequest.GetTypedHeaders().AcceptEncoding is not { Count: > 0 } acceptEncoding)
{
return false;
}

for (int i = 0; i < acceptEncoding.Count; i++)
{
if (string.Equals(acceptEncoding[i], GZipEncodingValue, StringComparison.OrdinalIgnoreCase))
if (string.Equals(acceptEncoding[i]?.Value.Value, GZipEncodingValue, StringComparison.OrdinalIgnoreCase))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO.Compression;
using System.Net;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using Microsoft.AspNetCore.Builder;
using Swashbuckle.AspNetCore.ReDoc;
Expand Down Expand Up @@ -219,8 +220,11 @@ public async Task ReDocMiddleware_Returns_ExpectedAssetContents_Decompressed()
Assert.Equal(response.Content.Headers.ContentLength, actual.Length);
}

[Fact]
public async Task ReDocMiddleware_Returns_ExpectedAssetContents_GZip_Compressed()
[Theory]
[InlineData("gzip")]
[InlineData("gzip;q=1.0, identity; q=0.5, *;q=0")]
[InlineData("gzip, deflate, br, zstd")]
public async Task ReDocMiddleware_Returns_ExpectedAssetContents_GZip_Compressed(string acceptEncoding)
{
// Arrange
var cancellationToken = TestContext.Current.CancellationToken;
Expand All @@ -229,7 +233,15 @@ public async Task ReDocMiddleware_Returns_ExpectedAssetContents_GZip_Compressed(
using var client = site.BuildClient();

using var request = new HttpRequestMessage(HttpMethod.Get, "/Api-Docs/redoc.standalone.js");
request.Headers.AcceptEncoding.Add(new("gzip"));

var encodings = acceptEncoding.Split(',')
.Select((p) => p.Trim())
.ToList();

foreach (var encoding in encodings)
{
request.Headers.AcceptEncoding.Add(StringWithQualityHeaderValue.Parse(encoding));
}

// Act
using var response = await client.SendAsync(request, cancellationToken);
Expand Down