From 00c32cbb35359c205c8e45981118de9d3b5a06ce Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 10 Aug 2013 12:58:30 -0700 Subject: [PATCH] properly respond to IfModifiedSince headers. should improve caching --- NzbDrone.Api/Extensions/ReqResExtensions.cs | 8 ++++++-- NzbDrone.Api/Frontend/StaticResourceProvider.cs | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/NzbDrone.Api/Extensions/ReqResExtensions.cs b/NzbDrone.Api/Extensions/ReqResExtensions.cs index 322217cc4..fd9980347 100644 --- a/NzbDrone.Api/Extensions/ReqResExtensions.cs +++ b/NzbDrone.Api/Extensions/ReqResExtensions.cs @@ -3,14 +3,18 @@ using System.Collections.Generic; using System.IO; using Nancy; using Nancy.Responses; +using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Serializer; namespace NzbDrone.Api.Extensions { - public static class JsonExtensions + public static class ReqResExtensions { private static readonly NancyJsonSerializer NancySerializer = new NancyJsonSerializer(); + + public static readonly string LastModified = BuildInfo.BuildDateTime.ToString("r"); + public static T FromJson(this Stream body) where T : class, new() { return FromJson(body, typeof(T)); @@ -51,7 +55,7 @@ namespace NzbDrone.Api.Extensions { headers["Cache-Control"] = "max-age=31536000 , public"; headers["Expires"] = "Sat, 29 Jun 2020 00:00:00 GMT"; - headers["Last-Modified"] = "Sat, 29 Jun 2000 00:00:00 GMT"; + headers["Last-Modified"] = LastModified; headers["Age"] = "193266"; return headers; diff --git a/NzbDrone.Api/Frontend/StaticResourceProvider.cs b/NzbDrone.Api/Frontend/StaticResourceProvider.cs index 698bd77d7..1d2c6fb57 100644 --- a/NzbDrone.Api/Frontend/StaticResourceProvider.cs +++ b/NzbDrone.Api/Frontend/StaticResourceProvider.cs @@ -48,6 +48,13 @@ namespace NzbDrone.Api.Frontend return null; } + if (context.Request.Headers.IfModifiedSince.HasValue) + { + var response = new Response { ContentType = MimeTypes.GetMimeType(path), StatusCode = HttpStatusCode.NotModified }; + _addCacheHeaders.ToResponse(context.Request, response); + return response; + } + var mapper = _requestMappers.SingleOrDefault(m => m.CanHandle(path)); if (mapper != null)