|
|
|
@ -1,19 +1,30 @@
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Nancy;
|
|
|
|
|
using Nancy.Bootstrapper;
|
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Extensions.Pipelines
|
|
|
|
|
{
|
|
|
|
|
public class GzipCompressionPipeline : IRegisterNancyPipeline
|
|
|
|
|
{
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
public GzipCompressionPipeline(Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Register(IPipelines pipelines)
|
|
|
|
|
{
|
|
|
|
|
pipelines.AfterRequest.AddItemToEndOfPipeline(c => CompressResponse(c.Request, c.Response));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response CompressResponse(Request request, Response response)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!response.ContentType.Contains("image")
|
|
|
|
|
&& request.Headers.AcceptEncoding.Any(x => x.Contains("gzip"))
|
|
|
|
@ -44,5 +55,12 @@ namespace NzbDrone.Api.Extensions.Pipelines
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Unable to gzip response", ex);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|