From 3427f18021f7201f7c09ad9926906c9324caafe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Kottal?= Date: Wed, 28 Aug 2024 11:41:36 +0200 Subject: [PATCH] Adds MaxAge cache header to ImageMetaData to prevent unnecessary meta data lookups through http --- .../RemoteImageResolver.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ImageSharpCommunity.Providers.Remote/RemoteImageResolver.cs b/src/ImageSharpCommunity.Providers.Remote/RemoteImageResolver.cs index 11ceaba..b2e8718 100644 --- a/src/ImageSharpCommunity.Providers.Remote/RemoteImageResolver.cs +++ b/src/ImageSharpCommunity.Providers.Remote/RemoteImageResolver.cs @@ -36,7 +36,12 @@ public async Task GetMetaDataAsync() _logger.LogDebug("LastModified header missing from {Url}", _url); } - return new ImageMetadata(response.Content.Headers.LastModified.GetValueOrDefault().UtcDateTime, response.Content.Headers.ContentLength.GetValueOrDefault()); + if (response.Headers.CacheControl?.MaxAge is null) + { + _logger.LogDebug("MaxAge header is null from {Url}", _url); + } + + return new ImageMetadata(response.Content.Headers.LastModified.GetValueOrDefault().UtcDateTime, (response.Headers.CacheControl?.MaxAge).GetValueOrDefault(), response.Content.Headers.ContentLength.GetValueOrDefault()); } public async Task OpenReadAsync()