1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

properly respond to IfModifiedSince headers. should improve caching

This commit is contained in:
kay.one 2013-08-10 12:58:30 -07:00
parent d339d1208f
commit 00c32cbb35
2 changed files with 13 additions and 2 deletions

View File

@ -3,14 +3,18 @@
using System.IO; using System.IO;
using Nancy; using Nancy;
using Nancy.Responses; using Nancy.Responses;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Serializer; using NzbDrone.Common.Serializer;
namespace NzbDrone.Api.Extensions namespace NzbDrone.Api.Extensions
{ {
public static class JsonExtensions public static class ReqResExtensions
{ {
private static readonly NancyJsonSerializer NancySerializer = new NancyJsonSerializer(); private static readonly NancyJsonSerializer NancySerializer = new NancyJsonSerializer();
public static readonly string LastModified = BuildInfo.BuildDateTime.ToString("r");
public static T FromJson<T>(this Stream body) where T : class, new() public static T FromJson<T>(this Stream body) where T : class, new()
{ {
return FromJson<T>(body, typeof(T)); return FromJson<T>(body, typeof(T));
@ -51,7 +55,7 @@ public static IDictionary<string, string> EnableCache(this IDictionary<string, s
{ {
headers["Cache-Control"] = "max-age=31536000 , public"; headers["Cache-Control"] = "max-age=31536000 , public";
headers["Expires"] = "Sat, 29 Jun 2020 00:00:00 GMT"; 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"; headers["Age"] = "193266";
return headers; return headers;

View File

@ -48,6 +48,13 @@ public Response ProcessStaticResourceRequest(NancyContext context, string workin
return null; 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)); var mapper = _requestMappers.SingleOrDefault(m => m.CanHandle(path));
if (mapper != null) if (mapper != null)