mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Fixed: Do cache images returned through the API (3rd party app support)
This commit is contained in:
parent
fdddb13686
commit
8a18124212
@ -1,11 +1,18 @@
|
|||||||
using Nancy;
|
using Nancy;
|
||||||
using Nancy.Bootstrapper;
|
using Nancy.Bootstrapper;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Api.Frontend;
|
||||||
|
|
||||||
namespace NzbDrone.Api.Extensions.Pipelines
|
namespace NzbDrone.Api.Extensions.Pipelines
|
||||||
{
|
{
|
||||||
public class NzbDroneVersionPipeline : IRegisterNancyPipeline
|
public class CacheHeaderPipeline : IRegisterNancyPipeline
|
||||||
{
|
{
|
||||||
|
private readonly ICacheableSpecification _cacheableSpecification;
|
||||||
|
|
||||||
|
public CacheHeaderPipeline(ICacheableSpecification cacheableSpecification)
|
||||||
|
{
|
||||||
|
_cacheableSpecification = cacheableSpecification;
|
||||||
|
}
|
||||||
|
|
||||||
public void Register(IPipelines pipelines)
|
public void Register(IPipelines pipelines)
|
||||||
{
|
{
|
||||||
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
|
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
|
||||||
@ -13,9 +20,13 @@ public void Register(IPipelines pipelines)
|
|||||||
|
|
||||||
private void Handle(NancyContext context)
|
private void Handle(NancyContext context)
|
||||||
{
|
{
|
||||||
if (!context.Response.Headers.ContainsKey("X-ApplicationVersion"))
|
if (_cacheableSpecification.IsCacheable(context))
|
||||||
{
|
{
|
||||||
context.Response.Headers.Add("X-ApplicationVersion", BuildInfo.Version.ToString());
|
context.Response.Headers.EnableCache();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.Headers.DisableCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
using Nancy;
|
using Nancy;
|
||||||
using Nancy.Bootstrapper;
|
using Nancy.Bootstrapper;
|
||||||
using NzbDrone.Api.Frontend;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
namespace NzbDrone.Api.Extensions.Pipelines
|
namespace NzbDrone.Api.Extensions.Pipelines
|
||||||
{
|
{
|
||||||
public class CacheHeaderPipeline : IRegisterNancyPipeline
|
public class NzbDroneVersionPipeline : IRegisterNancyPipeline
|
||||||
{
|
{
|
||||||
private readonly ICacheableSpecification _cacheableSpecification;
|
|
||||||
|
|
||||||
public CacheHeaderPipeline(ICacheableSpecification cacheableSpecification)
|
|
||||||
{
|
|
||||||
_cacheableSpecification = cacheableSpecification;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Register(IPipelines pipelines)
|
public void Register(IPipelines pipelines)
|
||||||
{
|
{
|
||||||
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
|
pipelines.AfterRequest.AddItemToStartOfPipeline(Handle);
|
||||||
@ -20,13 +13,9 @@ public void Register(IPipelines pipelines)
|
|||||||
|
|
||||||
private void Handle(NancyContext context)
|
private void Handle(NancyContext context)
|
||||||
{
|
{
|
||||||
if (_cacheableSpecification.IsCacheable(context))
|
if (!context.Response.Headers.ContainsKey("X-ApplicationVersion"))
|
||||||
{
|
{
|
||||||
context.Response.Headers.EnableCache();
|
context.Response.Headers.Add("X-ApplicationVersion", BuildInfo.Version.ToString());
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
context.Response.Headers.DisableCache();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Nancy;
|
using Nancy;
|
||||||
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
namespace NzbDrone.Api.Frontend
|
namespace NzbDrone.Api.Frontend
|
||||||
@ -20,7 +21,13 @@ public bool IsCacheable(NancyContext context)
|
|||||||
|
|
||||||
if (context.Request.Query.v == BuildInfo.Version) return true;
|
if (context.Request.Query.v == BuildInfo.Version) return true;
|
||||||
|
|
||||||
if (context.Request.Path.StartsWith("/api", StringComparison.CurrentCultureIgnoreCase)) return false;
|
if (context.Request.Path.StartsWith("/api", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
if (context.Request.Path.ContainsIgnoreCase("/MediaCover")) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (context.Request.Path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase)) return false;
|
if (context.Request.Path.StartsWith("/signalr", StringComparison.CurrentCultureIgnoreCase)) return false;
|
||||||
if (context.Request.Path.EndsWith("main.js")) return false;
|
if (context.Request.Path.EndsWith("main.js")) return false;
|
||||||
if (context.Request.Path.StartsWith("/feed", StringComparison.CurrentCultureIgnoreCase)) return false;
|
if (context.Request.Path.StartsWith("/feed", StringComparison.CurrentCultureIgnoreCase)) return false;
|
@ -1,8 +1,4 @@
|
|||||||
using System;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Nancy;
|
using Nancy;
|
||||||
using Nancy.Responses;
|
using Nancy.Responses;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
|
@ -122,14 +122,14 @@
|
|||||||
<Compile Include="Episodes\EpisodeResource.cs" />
|
<Compile Include="Episodes\EpisodeResource.cs" />
|
||||||
<Compile Include="Episodes\RenameEpisodeModule.cs" />
|
<Compile Include="Episodes\RenameEpisodeModule.cs" />
|
||||||
<Compile Include="Episodes\RenameEpisodeResource.cs" />
|
<Compile Include="Episodes\RenameEpisodeResource.cs" />
|
||||||
<Compile Include="Extensions\Pipelines\CacheHeaderPipeline.cs" />
|
|
||||||
<Compile Include="Extensions\Pipelines\NzbDroneVersionPipeline.cs" />
|
<Compile Include="Extensions\Pipelines\NzbDroneVersionPipeline.cs" />
|
||||||
|
<Compile Include="Extensions\Pipelines\CacheHeaderPipeline.cs" />
|
||||||
<Compile Include="Extensions\Pipelines\GZipPipeline.cs" />
|
<Compile Include="Extensions\Pipelines\GZipPipeline.cs" />
|
||||||
<Compile Include="Extensions\Pipelines\IfModifiedPipeline.cs" />
|
<Compile Include="Extensions\Pipelines\IfModifiedPipeline.cs" />
|
||||||
<Compile Include="Extensions\Pipelines\IRegisterNancyPipeline.cs" />
|
<Compile Include="Extensions\Pipelines\IRegisterNancyPipeline.cs" />
|
||||||
<Compile Include="Extensions\NancyJsonSerializer.cs" />
|
<Compile Include="Extensions\NancyJsonSerializer.cs" />
|
||||||
<Compile Include="Extensions\RequestExtensions.cs" />
|
<Compile Include="Extensions\RequestExtensions.cs" />
|
||||||
<Compile Include="Frontend\IsCacheableSpecification.cs" />
|
<Compile Include="Frontend\CacheableSpecification.cs" />
|
||||||
<Compile Include="Frontend\Mappers\UpdateLogFileMapper.cs" />
|
<Compile Include="Frontend\Mappers\UpdateLogFileMapper.cs" />
|
||||||
<Compile Include="Frontend\Mappers\BackupFileMapper.cs" />
|
<Compile Include="Frontend\Mappers\BackupFileMapper.cs" />
|
||||||
<Compile Include="Frontend\Mappers\FaviconMapper.cs" />
|
<Compile Include="Frontend\Mappers\FaviconMapper.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user