【发布时间】:2014-10-22 20:24:13
【问题描述】:
如何检测是否为我的 HTTP 模块中的特定请求启用了 GZIP?我对输出应用了一个过滤器,当它作用于 gzip 压缩的内容时,它会以某种方式破坏压缩,并且客户端浏览器会抛出一个无法解码内容的错误。
public void Init(HttpApplication context)
{
// if(HttpContext.Current.IsCompressed) // Check for compressed content here
// Set up the filter / replacement.
context.PostReleaseRequestState += (_, __) =>
{
var filterStream = new ResponseFilterStream(HttpContext.Current.Response.Filter);
filterStream.TransformString += FilterPage;
HttpContext.Current.Response.Filter = filterStream;
};
}
ResponseFilterStream 是一个自定义流,它缓存所有流写入并将内容呈现为事件,以便允许方法修改流的内容。它非常适合修改 HTML 请求(这是我想要的),但我不希望它作用于 gzip 压缩的响应。如何检测 gzipped 响应并防止过滤器流与响应挂钩?
【问题讨论】:
-
类似
if (response.Filter is System.IO.Compression.GZipStream)?
标签: c# gzip httpmodule