Skip to content

Commit 7161f4f

Browse files
Added content encoding to the function that detects compressed sitemaps. I ran into a site that was gzipping sitemap entries and they weren't being detected properly.
1 parent 4ac4cdb commit 7161f4f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/TurnerSoftware.SitemapTools/SitemapQuery.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ public async Task<IEnumerable<Uri>> DiscoverSitemapsAsync(string domainName, Can
131131
return result;
132132
}
133133

134-
private static bool IsCompressedStream(string contentType) =>
134+
private static bool IsCompressedStream(string contentType, ICollection<string> contentEncoding) =>
135135
contentType.Equals("application/x-gzip", StringComparison.InvariantCultureIgnoreCase) ||
136-
contentType.Equals("application/octet-stream", StringComparison.InvariantCultureIgnoreCase);
136+
contentType.Equals("application/octet-stream", StringComparison.InvariantCultureIgnoreCase) ||
137+
contentEncoding.Contains("x-gzip");
137138

138139
/// <summary>
139140
/// Retrieves a sitemap at the given URI, converting it to a <see cref="SitemapFile"/>.
@@ -149,9 +150,10 @@ private static bool IsCompressedStream(string contentType) =>
149150
if (response.IsSuccessStatusCode)
150151
{
151152
var contentType = response.Content.Headers.ContentType.MediaType;
153+
var contentEncoding = response.Content.Headers.ContentEncoding;
152154
var requiresManualDecompression = false;
153-
154-
if (IsCompressedStream(contentType))
155+
156+
if (IsCompressedStream(contentType, contentEncoding))
155157
{
156158
requiresManualDecompression = true;
157159
var baseFileName = Path.GetFileNameWithoutExtension(sitemapUrl.AbsolutePath);

0 commit comments

Comments
 (0)