From 9df49cc7961e9442e888f97f9d5cc2c3af706809 Mon Sep 17 00:00:00 2001 From: Vasily Date: Tue, 14 Apr 2020 01:52:43 +0300 Subject: [PATCH 1/3] Make Last-Modified and If-Modified-Since headers follow the spec --- .../HttpServer/HttpResultFactory.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index 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 /// 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"); + /// /// The logger. /// @@ -420,7 +426,11 @@ namespace Emby.Server.Implementations.HttpServer if (!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.HttpServer if (lastModifiedDate.HasValue) { - responseHeaders[HeaderNames.LastModified] = lastModifiedDate.Value.ToString(CultureInfo.InvariantCulture); + responseHeaders[HeaderNames.LastModified] = lastModifiedDate.Value.ToUniversalTime().ToString(HttpDateFormat, _enUSculture); } } From 95dc99fdbda1067d9392649a47110448bc6b9187 Mon Sep 17 00:00:00 2001 From: Vasily Date: Thu, 16 Apr 2020 01:03:29 +0300 Subject: [PATCH 2/3] Update Emby.Server.Implementations/HttpServer/HttpResultFactory.cs Co-Authored-By: Bond-009 --- Emby.Server.Implementations/HttpServer/HttpResultFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index 3b1563fdda..d394c56ad2 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -32,7 +32,7 @@ namespace Emby.Server.Implementations.HttpServer // 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"); + private static readonly CultureInfo _enUSculture = new CultureInfo("en-US", false); /// /// The logger. From d62bd7fecd3789cacad6618c9992bb028a5049fa Mon Sep 17 00:00:00 2001 From: dkanada Date: Sun, 19 Apr 2020 11:46:22 +0900 Subject: [PATCH 3/3] fix spelling error --- Emby.Server.Implementations/HttpServer/HttpResultFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index d394c56ad2..464ca3a0b5 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -31,7 +31,7 @@ namespace Emby.Server.Implementations.HttpServer // 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 + // We specifically use en-US culture because both day of week and month names require it private static readonly CultureInfo _enUSculture = new CultureInfo("en-US", false); ///