gpt4 book ai didi

c# - 我可以检测我的 HttpModule 中的内容是否已压缩吗?

转载 作者:太空狗 更新时间:2023-10-29 21:52:01 26 4
gpt4 key购买 nike

我有一个 HttpModule,用于动态压缩来自 ASP.NET (MVC3) Web 应用程序的内容。该方法与 this article 中的 CompressionModule 非常相似(模块将 GZip 过滤器应用于 HttpResponse 并设置正确的内容编码 header )。

出于这样那样的原因,这需要在经典模式下运行,而不是集成管道模式。

我遇到的问题是,在某些启用了 IIS 压缩的服务器上,IIS 压缩内容,然后我的模块压缩它。

结果是我使用编码对内容进行了两次压缩:

Content-encoding: gzip,gzip

一个来自 IIS,一个来 self 代码中的这一行:

 httpResponse.AppendHeader("Content-encoding", "gzip");

有谁知道在经典模式下,我可以检查内容是否已经压缩,服务器是否启用了压缩,以便绕过我自己的压缩?

在管道模式下,这个检查很简单

if (httpResponse.Headers["Content-encoding"]!= null)
{
return;
}

即检查是否有任何内容已经设置了内容编码,如果是,什么也不做。

但是,我在经典模式中遇到了困难。不幸的是,在经典模式下不允许访问 HttpResponse.Headers,因此我无法进行屏障检查。

感谢收到所有想法。

最佳答案

理论上,您可以使用反射来查看 HttpRequest._cacheHeaders 字段,ASP.NET 显然在经典模式下存储所有尚未发送的 header :

if (this._wr is IIS7WorkerRequest)
{
this.Headers.Add(HttpResponseHeader.MaybeEncodeHeader(name), HttpResponseHeader.MaybeEncodeHeader(value));
}
else if (flag)
{
if (this._cacheHeaders == null)
{
this._cacheHeaders = new ArrayList();
}
this._cacheHeaders.Add(new HttpResponseHeader(knownResponseHeaderIndex, value));
}

关于c# - 我可以检测我的 HttpModule 中的内容是否已压缩吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5434858/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com