You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1017 B
28 lines
1017 B
|
|
using DefenseWeb.Helper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Web;
|
|
using System.Web.Http.Filters;
|
|
|
|
namespace DefenseWeb.Attribute
|
|
{
|
|
public class DeflateCompressionAttribute : ActionFilterAttribute
|
|
{
|
|
|
|
public override void OnActionExecuted(HttpActionExecutedContext actContext)
|
|
{
|
|
var content = actContext.Response.Content;
|
|
var bytes = content == null ? null : content.ReadAsByteArrayAsync().Result;
|
|
var zlibbedContent = bytes == null ? new byte[0] :
|
|
CompressionHelper.DeflateByte(bytes);
|
|
actContext.Response.Content = new ByteArrayContent(zlibbedContent);
|
|
actContext.Response.Content.Headers.Remove("Content-Type");
|
|
actContext.Response.Content.Headers.Add("Content-encoding", "deflate");
|
|
actContext.Response.Content.Headers.Add("Content-Type", "application/json");
|
|
base.OnActionExecuted(actContext);
|
|
}
|
|
}
|
|
}
|