問題
使用 gzip/deflate壓縮responsed資料
解決方法
Code
public static HttpContext compressResponsed(HttpContext context) { string acceptEncoding = context.Request.Headers["Accept-Encoding"].ToString().ToUpperInvariant(); if (!String.IsNullOrEmpty(acceptEncoding)) { if (acceptEncoding.Contains("GZIP")) { context.Response.AppendHeader("Content-encoding", "gzip"); context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress); } else if (acceptEncoding.Contains("DEFLATE")) { context.Response.AppendHeader("Content-encoding", "deflate"); context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress); } } return context; }使用方式
public void ProcessRequest(HttpContext context)
{
context = Utlity.compressResponsed(context);
// context.Response.Write(xxx)
}
沒有留言:
張貼留言