我特林實現什麼史蒂夫Souders的討論http://www.stevesouders.com/blog/2010/07/12/velocity-forcing-gzip-compression/有關強制gzip壓縮我試圖強制使用GZipStream在頁面上gzip壓縮,但瀏覽器說我使用不支持壓縮
我有一個模塊的運行這樣的:
void context_PreSendRequestHeaders(object sender, EventArgs e)
{
var app = sender as HttpApplication;
var request = app.Request;
var response = app.Response;
if (CompressionUtils.GzipSupported(request) || CompressionUtils.GzipNotSupportedExplicitly(request))
{
return;
}
if (CompressionUtils.GzipSupportedExplicitly(request))
{
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
response.AddHeader(HttpHeaderKey.ContentEncoding, "gzip");
return;
}
response.Write("<iframe style=\"display:none;\" src=\"/CompressedPage.aspx\"></iframe>");
}
CompressionUtils.GzipSupported
只檢查了「編碼接受 - 」標題,而 CompressionUtils.GzipSupportedExplicitly
和CompressionUtils.GzipNotSupportedExplicitly
檢查的cookie說瀏覽器是否真的能夠讀取gzip的
但是,當我在Firefox加載頁面我得到這個錯誤:
Content Encoding Error
The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.
和提琴手它表明content-encoding頭已被添加,但內容沒有被壓縮