mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-17 02:49:05 -07:00
37 lines
932 B
C#
37 lines
932 B
C#
|
using System.IO;
|
|||
|
using System.IO.Compression;
|
|||
|
using MediaBrowser.Common.Json;
|
|||
|
|
|||
|
namespace MediaBrowser.Common.Net.Handlers
|
|||
|
{
|
|||
|
public abstract class JsonHandler : Response
|
|||
|
{
|
|||
|
public JsonHandler(RequestContext ctx)
|
|||
|
: base(ctx)
|
|||
|
{
|
|||
|
Headers["Content-Encoding"] = "gzip";
|
|||
|
|
|||
|
WriteStream = s =>
|
|||
|
{
|
|||
|
WriteReponse(s);
|
|||
|
s.Close();
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public override string ContentType
|
|||
|
{
|
|||
|
get { return "application/json"; }
|
|||
|
}
|
|||
|
|
|||
|
protected abstract object ObjectToSerialize { get; }
|
|||
|
|
|||
|
private void WriteReponse(Stream stream)
|
|||
|
{
|
|||
|
using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Compress, false))
|
|||
|
{
|
|||
|
JsonSerializer.Serialize(ObjectToSerialize, gzipStream);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|