【发布时间】:2012-05-17 16:07:20
【问题描述】:
我只是想调整我的方法以在浏览器接受 gzip 时传输压缩数据。 else 部分已经有效。我只想调整if 部分。代码如下:
private void writeBytes()
{
var response = this.context.Response;
if (canGzip)
{
response.AppendHeader("Content-Encoding", "gzip");
//COMPRESS WITH GZipStream
}
else
{
response.AppendHeader("Content-Length", this.responseBytes.Length.ToString());
response.ContentType = this.isScript ? "text/javascript" : "text/css";
response.AppendHeader("Content-Encoding", "utf-8");
response.ContentEncoding = Encoding.Unicode;
response.OutputStream.Write(this.responseBytes, 0, this.responseBytes.Length);
response.Flush();
}
}
【问题讨论】:
-
您为什么不使用 Web 服务器配置来压缩数据?