diff options
| -rw-r--r-- | MediaBrowser.Api/HttpHandlers/ImageHandler.cs | 17 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/Handlers/BaseHandler.cs | 18 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Drawing/BaseImageProcessor.cs | 6 |
3 files changed, 38 insertions, 3 deletions
diff --git a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs index c168569cd..d3aaf27ff 100644 --- a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs @@ -137,6 +137,23 @@ namespace MediaBrowser.Api.HttpHandlers return date;
}
+ protected override async Task<string> GetETag()
+ {
+ string tag = string.Empty;
+
+ var entity = await GetSourceEntity().ConfigureAwait(false);
+
+ foreach (var processor in Kernel.Instance.ImageProcessors)
+ {
+ if (processor.IsConfiguredToProcess(entity, ImageType, ImageIndex))
+ {
+ tag += processor.ProcessingConfigurationDateLastModifiedUtc.Ticks.ToString();
+ }
+ }
+
+ return tag;
+ }
+
private int ImageIndex
{
get
diff --git a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs index 1a014395a..ab12cb2cf 100644 --- a/MediaBrowser.Common/Net/Handlers/BaseHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/BaseHandler.cs @@ -192,6 +192,13 @@ namespace MediaBrowser.Common.Net.Handlers ctx.Response.ContentType = await GetContentType().ConfigureAwait(false);
+ string etag = await GetETag().ConfigureAwait(false);
+
+ if (!string.IsNullOrEmpty(etag))
+ {
+ ctx.Response.Headers["ETag"] = etag;
+ }
+
TimeSpan cacheDuration = CacheDuration;
DateTime? lastDateModified = await GetLastDateModified().ConfigureAwait(false);
@@ -205,7 +212,11 @@ namespace MediaBrowser.Common.Net.Handlers // If the cache hasn't expired yet just return a 304
if (IsCacheValid(ifModifiedSince.ToUniversalTime(), cacheDuration, lastDateModified))
{
- StatusCode = 304;
+ // ETag must also match (if supplied)
+ if ((etag ?? string.Empty).Equals(ctx.Request.Headers["If-None-Match"] ?? string.Empty))
+ {
+ StatusCode = 304;
+ }
}
}
}
@@ -311,6 +322,11 @@ namespace MediaBrowser.Common.Net.Handlers response.Headers[HttpResponseHeader.LastModified] = lastModified.ToString("r");
}
+ protected virtual Task<string> GetETag()
+ {
+ return Task.FromResult<string>(string.Empty);
+ }
+
/// <summary>
/// Gives subclasses a chance to do any prep work, and also to validate data and set an error status code, if needed
/// </summary>
diff --git a/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs b/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs index 8fc6564e7..a1441cf7f 100644 --- a/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs @@ -83,12 +83,14 @@ namespace MediaBrowser.Controller.Drawing }
}
+ private static DateTime testDate = DateTime.UtcNow;
+
public override DateTime ProcessingConfigurationDateLastModifiedUtc
{
get
{
- // This will result in a situation where images are never cached, but again, this is a prototype
- return DateTime.UtcNow;
+ // This will result in a situation where images are only cached throughout a server session, but again, this is a prototype
+ return testDate;
}
}
|
