1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 16:02:29 +01:00

fixed gzip for static resource.

This commit is contained in:
kay.one 2013-07-06 20:56:33 -07:00
parent 92c3fe61f2
commit 51fb6376b9
2 changed files with 18 additions and 6 deletions

View File

@ -9,14 +9,19 @@ namespace NzbDrone.Api.Extensions
{ {
public static void Handle(NancyContext context) 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(); var data = new MemoryStream();
context.Response.Contents.Invoke(data); response.Contents.Invoke(data);
data.Position = 0; data.Position = 0;
if (data.Length < 1024) if (data.Length < 1024)
{ {
context.Response.Contents = stream => response.Contents = stream =>
{ {
data.CopyTo(stream); data.CopyTo(stream);
stream.Flush(); stream.Flush();
@ -24,8 +29,8 @@ namespace NzbDrone.Api.Extensions
} }
else else
{ {
context.Response.Headers["Content-Encoding"] = "gzip"; response.Headers["Content-Encoding"] = "gzip";
context.Response.Contents = s => response.Contents = s =>
{ {
var gzip = new GZipStream(s, CompressionMode.Compress, true); var gzip = new GZipStream(s, CompressionMode.Compress, true);
data.CopyTo(gzip); data.CopyTo(gzip);
@ -33,6 +38,8 @@ namespace NzbDrone.Api.Extensions
}; };
} }
} }
return response;
} }
} }
} }

View File

@ -48,7 +48,12 @@ namespace NzbDrone.Api.Series
return new NotFoundResponse(); return new NotFoundResponse();
} }
return series.AsResponse();
var resource = ToResource(()=>_seriesService.FindBySlug(slug));
MapCoversToLocal(resource);
return resource.AsResponse();
} }
private List<SeriesResource> AllSeries() private List<SeriesResource> AllSeries()