The Free Software Media System - Server Backend & API
Make Last-Modified and If-Modified-Since headers follow the spec
Vasily9df49cc7961e
diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.csindex b42662420b..3b1563fdda 100644--- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs+++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs@@ -28,6 +28,12 @@ namespace Emby.Server.Implementations.HttpServer/// </summary>public class HttpResultFactory : IHttpResultFactory{+ // Last-Modified and If-Modified-Since must follow strict date format,+ // see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since+ private const string HttpDateFormat = "ddd, dd MMM yyyy HH:mm:ss \"GMT\"";+ // We specifically use en-US culture because both day of week and month names must be in it9+ private static readonly CultureInfo _enUSculture = CultureInfo.CreateSpecificCulture("en-US");+/// <summary>/// The logger./// </summary>@@ -420,7 +426,11 @@ namespace Emby.Server.Implementations.HttpServerif (!noCache){- DateTime.TryParse(requestContext.Headers[HeaderNames.IfModifiedSince], out var ifModifiedSinceHeader);+ if (!DateTime.TryParseExact(requestContext.Headers[HeaderNames.IfModifiedSince], HttpDateFormat, _enUSculture, DateTimeStyles.AssumeUniversal, out var ifModifiedSinceHeader))+ {+ _logger.LogDebug("Failed to parse If-Modified-Since header date: {0}", requestContext.Headers[HeaderNames.IfModifiedSince]);+ return null;+ }if (IsNotModified(ifModifiedSinceHeader, options.CacheDuration, options.DateLastModified)){@@ -629,7 +639,7 @@ namespace Emby.Server.Implementations.HttpServerif (lastModifiedDate.HasValue){- responseHeaders[HeaderNames.LastModified] = lastModifiedDate.Value.ToString(CultureInfo.InvariantCulture);+ responseHeaders[HeaderNames.LastModified] = lastModifiedDate.Value.ToUniversalTime().ToString(HttpDateFormat, _enUSculture);}}