Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SocketsHttpHandler's content encoding comparison case-insensitive #98475

Merged
merged 1 commit into from
Feb 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class HttpClientHandler_Decompression_Test : HttpClientHandlerTe
public HttpClientHandler_Decompression_Test(ITestOutputHelper output) : base(output) { }

public static IEnumerable<object[]> DecompressedResponse_MethodSpecified_DecompressedContentReturned_MemberData() =>
from compressionName in new[] { "gzip", "zlib", "deflate", "br" }
from compressionName in new[] { "gzip", "GZIP", "zlib", "ZLIB", "deflate", "DEFLATE", "br", "BR" }
from all in new[] { false, true }
from copyTo in new[] { false, true }
from contentLength in new[] { 0, 1, 12345 }
Expand All @@ -40,7 +40,7 @@ public static IEnumerable<object[]> DecompressedResponse_MethodSpecified_Decompr
public async Task DecompressedResponse_MethodSpecified_DecompressedContentReturned(string compressionName, bool all, bool useCopyTo, int contentLength)
{
if (IsWinHttpHandler &&
(compressionName == "br" || compressionName == "zlib"))
(compressionName is "br" or "BR" or "zlib" or "ZLIB"))
{
// brotli and zlib not supported on WinHttpHandler
return;
Expand All @@ -52,24 +52,28 @@ public async Task DecompressedResponse_MethodSpecified_DecompressedContentReturn
switch (compressionName)
{
case "gzip":
case "GZIP":
compress = s => new GZipStream(s, CompressionLevel.Optimal, leaveOpen: true);
methods = all ? DecompressionMethods.GZip : _all;
break;

#if !NETFRAMEWORK
case "br":
case "BR":
compress = s => new BrotliStream(s, CompressionLevel.Optimal, leaveOpen: true);
methods = all ? DecompressionMethods.Brotli : _all;
break;

case "zlib":
case "ZLIB":
compress = s => new ZLibStream(s, CompressionLevel.Optimal, leaveOpen: true);
methods = all ? DecompressionMethods.Deflate : _all;
encodingName = "deflate";
break;
#endif

case "deflate":
case "DEFLATE":
compress = s => new DeflateStream(s, CompressionLevel.Optimal, leaveOpen: true);
methods = all ? DecompressionMethods.Deflate : _all;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ internal override async ValueTask<HttpResponseMessage> SendAsync(HttpRequestMess
last = encoding;
}

if (GZipEnabled && last == Gzip)
if (GZipEnabled && string.Equals(last, Gzip, StringComparison.OrdinalIgnoreCase))
{
response.Content = new GZipDecompressedContent(response.Content);
}
else if (DeflateEnabled && last == Deflate)
else if (DeflateEnabled && string.Equals(last, Deflate, StringComparison.OrdinalIgnoreCase))
{
response.Content = new DeflateDecompressedContent(response.Content);
}
else if (BrotliEnabled && last == Brotli)
else if (BrotliEnabled && string.Equals(last, Brotli, StringComparison.OrdinalIgnoreCase))
{
response.Content = new BrotliDecompressedContent(response.Content);
}
Expand Down
Loading