Internet Explorer 8 +放气 [英] Internet Explorer 8 + Deflate

查看:226
本文介绍了Internet Explorer 8 +放气的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常古怪的问题..我真的希望有人有答案,因为我不知道在哪里问。

I have a very weird problem.. I really do hope someone has an answer because I wouldn't know where else to ask.

我写一个cgi应用程序在C ++中由Apache执行并输出HTML代码。我自己在我的C ++应用程序中压缩HTML输出 - 因为我的web主机由于某种原因不支持mod_deflate。

I am writing a cgi application in C++ which is executed by Apache and outputs HTML code. I am compressing the HTML output myself - from within my C++ application - since my web host doesn't support mod_deflate for some reason.

我用Firefox 2,Firefox 3,Opera 9,Opera 10,谷歌浏览器,Safari浏览器,IE6,IE7,IE8,甚至wget ..它可以与任何除IE8。

I tested this with Firefox 2, Firefox 3, Opera 9, Opera 10, Google Chrome, Safari, IE6, IE7, IE8, even wget.. It works with ANYTHING except IE8.

IE8只是说Internet Explorer无法显示网页,没有任何信息。我知道这是因为压缩只是因为它可以工作,如果我禁用它。

IE8 just says "Internet Explorer cannot display the webpage", with no information whatsoever. I know it's because of the compression only because it works if I disable it.

你知道我做错了吗?

我使用zlib压缩它,并且确切的代码是:

I use zlib to compress it, and the exact code is:

    /* 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;
}


推荐答案

gzip和deflate方法相同...它们非常接近,但是与标题有一些细微的差别,因此,如果您更改内容编码,您还应该将参数更改为编码方法(具体来说,窗口大小)!

The gzip and deflate methods aren't the same... they are very close, but there are some subtle differences with the header, so, if you change your content-encoding, you should also change your parameters to the encoding method (specifically, the window size)!

请参阅: http://apcmag.com/improve_your_site_with_http_compression.htm

其他浏览器可能会忽略您的内容编码规范并进行自动识别,但IE8不是...

Probably the other browsers are ignoring your content-encoding specification and doing some automatic recognition, but IE8 is not...

请参阅: http://www.zlib.net/manual.html#deflateInit2

尝试使用:

method=Z_DEFLATED
windowBits=-15  (negative so that the header is suppressed)

并使用gzip作为内容编码

And use "gzip" as the content-encoding

这篇关于Internet Explorer 8 +放气的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆