我有个很奇怪的问题..。我真的希望有人能给我答案,因为我不知道还能问什么地方。
我正在用C++编写一个cgi应用程序,它由Apache执行并输出HTML代码。我自己正在压缩HTML输出--在我的C++应用程序中--因为我的web主机由于某种原因不支持mod_deflate。
我用Firefox 2,Firefox 3,Opera 9,Opera 10,Google,Safari,IE6,IE7,IE8,甚至wget进行了测试。它适用于,,除了IE8之外的任何东西。
IE8只是说"Internet不能显示网页“,没有任何信息。我知道这是因为压缩,只有当我禁用它的时候,它才能工作。
你知道我做错了什么吗?
我使用zlib压缩它,确切的代码是:
/* Compress it */
int compressed_output_size = content.length() + (content.length() * 0.2) + 16;
char *compressed_output = (char *)Alloc(compressed_output_size);
int compressed_output_length;
Compress(compressed_output, compressed_output_size, (void *)content.c_str(), content.length(), &compressed_output_length);
/* Send the compressed header */
cout << "Content-Encoding: deflate\r\n";
cout << boost::format("Content-Length: %d\r\n") % compressed_output_length;
cgiHeaderContentType("text/html");
cout.write(compressed_output, compressed_output_length);
static void Compress(void *to, size_t to_size, void *from, size_t from_size, int *final_size)
{
int ret;
z_stream stream;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
if ((ret = deflateInit(&stream, CompressionSpeed)) != Z_OK)
COMPRESSION_ERROR("deflateInit() failed: %d", ret);
stream.next_out = (Bytef *)to;
stream.avail_out = (uInt)to_size;
stream.next_in = (Bytef *)from;
stream.avail_in = (uInt)from_size;
if ((ret = deflate(&stream, Z_NO_FLUSH)) != Z_OK)
COMPRESSION_ERROR("deflate() failed: %d", ret);
if (stream.avail_in != 0)
COMPRESSION_ERROR("stream.avail_in is not 0 (it's %d)", stream.avail_in);
if ((ret = deflate(&stream, Z_FINISH)) != Z_STREAM_END)
COMPRESSION_ERROR("deflate() failed: %d", ret);
if ((ret = deflateEnd(&stream)) != Z_OK)
COMPRESSION_ERROR("deflateEnd() failed: %d", ret);
if (final_size)
*final_size = stream.total_out;
return;
}发布于 2009-07-03 20:16:06
gzip和泄气的方法不一样..。它们非常接近,但与标头有一些细微的差别,因此,如果更改内容编码,还应该将参数更改为编码方法(特别是窗口大小)!
请参阅:http://apcmag.com/improve_your_site_with_http_compression.htm
可能其他浏览器忽略了您的内容编码规范,并进行了一些自动识别,但IE8不是.
请参阅:http://www.zlib.net/manual.html#deflateInit2
试着使用:
method=Z_DEFLATED
windowBits=-15 (negative so that the header is suppressed)并使用"gzip“作为内容编码。
发布于 2010-03-29 20:48:53
我想澄清我在这上面发现了什么,因为我已经编写了自己的泄气算法,我自己的HTTP服务器,让我感到沮丧的是,IE8也没有识别我的泄气内容:
HTTP是http://www.faqs.org/ftp/rfc/rfc2616.pdf。第17页声明RFC 1950和RFC 1951在HTTP报头中执行泄气时使用。RFC 1950只是简单地定义标题和预告片字节;平减算法是在RFC 1951中定义的。当我将它编写成规范时,IE8失败了。
当我忽略RFC 1950,只做RFC 1951,它通过了。
因此,我认为IE8没有正确地遵循RFC 2616页面17,而且所有其他浏览器都可以接受这两种格式。
https://stackoverflow.com/questions/1077869
复制相似问题