mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-09 04:22:30 +01:00
added gzip after pipeline
This commit is contained in:
parent
6838298dbc
commit
9d8fd840c4
38
NzbDrone.Api/Extensions/GZipPipeline.cs
Normal file
38
NzbDrone.Api/Extensions/GZipPipeline.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
using Nancy;
|
||||||
|
|
||||||
|
namespace NzbDrone.Api.Extensions
|
||||||
|
{
|
||||||
|
public static class GzipCompressionPipeline
|
||||||
|
{
|
||||||
|
public static void Handle(NancyContext context)
|
||||||
|
{
|
||||||
|
if (!context.Response.ContentType.Contains("image") && context.Request.Headers.AcceptEncoding.Any(x => x.Contains("gzip")))
|
||||||
|
{
|
||||||
|
var data = new MemoryStream();
|
||||||
|
context.Response.Contents.Invoke(data);
|
||||||
|
data.Position = 0;
|
||||||
|
if (data.Length < 1024)
|
||||||
|
{
|
||||||
|
context.Response.Contents = stream =>
|
||||||
|
{
|
||||||
|
data.CopyTo(stream);
|
||||||
|
stream.Flush();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.Response.Headers["Content-Encoding"] = "gzip";
|
||||||
|
context.Response.Contents = s =>
|
||||||
|
{
|
||||||
|
var gzip = new GZipStream(s, CompressionMode.Compress, true);
|
||||||
|
data.CopyTo(gzip);
|
||||||
|
gzip.Close();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -38,6 +38,7 @@ protected override void ApplicationStartup(TinyIoCContainer container, IPipeline
|
|||||||
container.Resolve<IEnableBasicAuthInNancy>().Register(pipelines);
|
container.Resolve<IEnableBasicAuthInNancy>().Register(pipelines);
|
||||||
container.Resolve<IMessageAggregator>().PublishEvent(new ApplicationStartedEvent());
|
container.Resolve<IMessageAggregator>().PublishEvent(new ApplicationStartedEvent());
|
||||||
|
|
||||||
|
pipelines.AfterRequest.AddItemToStartOfPipeline(GzipCompressionPipeline.Handle);
|
||||||
|
|
||||||
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<NzbDroneErrorPipeline>().HandleException);
|
ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve<NzbDroneErrorPipeline>().HandleException);
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,7 @@
|
|||||||
<Compile Include="Directories\DirectoryModule.cs" />
|
<Compile Include="Directories\DirectoryModule.cs" />
|
||||||
<Compile Include="Episodes\EpisodeModule.cs" />
|
<Compile Include="Episodes\EpisodeModule.cs" />
|
||||||
<Compile Include="Episodes\EpisodeResource.cs" />
|
<Compile Include="Episodes\EpisodeResource.cs" />
|
||||||
|
<Compile Include="Extensions\GZipPipeline.cs" />
|
||||||
<Compile Include="Extensions\NancyJsonSerializer.cs" />
|
<Compile Include="Extensions\NancyJsonSerializer.cs" />
|
||||||
<Compile Include="Frontend\MediaCoverMapper.cs" />
|
<Compile Include="Frontend\MediaCoverMapper.cs" />
|
||||||
<Compile Include="Frontend\IMapHttpRequestsToDisk.cs" />
|
<Compile Include="Frontend\IMapHttpRequestsToDisk.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user