Internet Explorer 8 + 放气

发布于 2024-07-26 00:02:45 字数 1970 浏览 6 评论 0 原文

我有一个非常奇怪的问题..我真的希望有人能给出答案,因为我不知道还能去哪里问。

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

我用 Firefox 2、Firefox 3、Opera 9、Opera 10、Google Chrome、Safari、IE6、IE7、IE8,甚至 wget 进行了测试。它适用于除 IE8 之外的任何

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

你知道我做错了什么吗?

我使用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;
}

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

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.

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 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.

Do you know what I'm doing wrong?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

面犯桃花 2024-08-02 00:02:45

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

请参阅: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”作为内容编码

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)!

See: http://apcmag.com/improve_your_site_with_http_compression.htm

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

See: http://www.zlib.net/manual.html#deflateInit2

Try to use:

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

And use "gzip" as the content-encoding

两相知 2024-08-02 00:02:45

我想澄清一下我在这方面的发现,因为我已经编写了自己的放气算法、我自己的 HTTP 服务器,令我沮丧的是 IE8 也无法识别我的放气内容:

HTTP RFC 是 http://www.faqs.org/ftp/rfc/rfc2616.pdf。 第 17 页指出在 HTTP 标头中执行 deflate 时同时使用 RFC 1950 和 RFC 1951。 RFC 1950 只是定义了标头和尾部字节; deflate 算法在 RFC 1951 中定义。当我按照规范对其进行编程时,IE8 失败了。

当我忽略 RFC 1950 并只执行 RFC 1951 时,它就通过了。

那么,我会假设 IE8 没有正确遵循 RFC 2616 第 17 页,并且所有其他浏览器都足以接受这两种格式。

I wanted to clarify what I've discovered on this, as I've written my own deflate algorithm, my own HTTP server, and to my dismay IE8 also failed to recognize my deflated content:

HTTP RFC is http://www.faqs.org/ftp/rfc/rfc2616.pdf. Page 17 states both RFC 1950 and RFC 1951 is used when performing a deflate in the HTTP headers. RFC 1950 is simply defining the header and trailer bytes; the deflate algorithm is defined in RFC 1951. When I programmed this to spec, IE8 failed.

When I ignored RFC 1950 and only did RFC 1951, it passed.

I would assume, then, that IE8 isn't following RFC 2616 page 17 correctly, and all of the other browsers are nice enough to accept either format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文