mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
added gzip after pipeline
This commit is contained in:
parent
6838298dbc
commit
9d8fd840c4
3 changed files with 40 additions and 0 deletions
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();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue