From 51fb6376b92c7155b424656d43c5b8bc4db52281 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 6 Jul 2013 20:56:33 -0700 Subject: [PATCH] fixed gzip for static resource. --- NzbDrone.Api/Extensions/GZipPipeline.cs | 17 ++++++++++++----- NzbDrone.Api/Series/SeriesModule.cs | 7 ++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/NzbDrone.Api/Extensions/GZipPipeline.cs b/NzbDrone.Api/Extensions/GZipPipeline.cs index 86767f2e4..4dac9bc4b 100644 --- a/NzbDrone.Api/Extensions/GZipPipeline.cs +++ b/NzbDrone.Api/Extensions/GZipPipeline.cs @@ -9,14 +9,19 @@ namespace NzbDrone.Api.Extensions { public static void Handle(NancyContext context) { - if (!context.Response.ContentType.Contains("image") && context.Request.Headers.AcceptEncoding.Any(x => x.Contains("gzip"))) + context.Response.CompressResponse(context.Request); + } + + public static Response CompressResponse(this Response response, Request request) + { + if (!response.ContentType.Contains("image") && request.Headers.AcceptEncoding.Any(x => x.Contains("gzip"))) { var data = new MemoryStream(); - context.Response.Contents.Invoke(data); + response.Contents.Invoke(data); data.Position = 0; if (data.Length < 1024) { - context.Response.Contents = stream => + response.Contents = stream => { data.CopyTo(stream); stream.Flush(); @@ -24,8 +29,8 @@ namespace NzbDrone.Api.Extensions } else { - context.Response.Headers["Content-Encoding"] = "gzip"; - context.Response.Contents = s => + response.Headers["Content-Encoding"] = "gzip"; + response.Contents = s => { var gzip = new GZipStream(s, CompressionMode.Compress, true); data.CopyTo(gzip); @@ -33,6 +38,8 @@ namespace NzbDrone.Api.Extensions }; } } + + return response; } } } \ No newline at end of file diff --git a/NzbDrone.Api/Series/SeriesModule.cs b/NzbDrone.Api/Series/SeriesModule.cs index 217bd7e4e..86cab1a8e 100644 --- a/NzbDrone.Api/Series/SeriesModule.cs +++ b/NzbDrone.Api/Series/SeriesModule.cs @@ -48,7 +48,12 @@ namespace NzbDrone.Api.Series return new NotFoundResponse(); } - return series.AsResponse(); + + var resource = ToResource(()=>_seriesService.FindBySlug(slug)); + + MapCoversToLocal(resource); + + return resource.AsResponse(); } private List AllSeries()