分块传输编码浏览器体验

时间:2013-06-17 17:06:35

标签: perl apache http encoding http-headers

为什么输出这个简单的Perl脚本>>

print "Content-type: text/plain\n";
print "Transfer-Encoding: chunked\n\n";
print "11\n\n";
print "0123456789ABCDEF\n";
print "11\n\n";
print "0123456789ABCDEF\n";
print "0\n\n";

...适用于Chrome浏览器,不适用于IE10 ..?

1 个答案:

答案 0 :(得分:5)

您已经实现了chunked transfer coding错误:每个块包含以十六进制表示法的字节块大小,后跟CRLF序列,后跟块数据:

   chunk          = chunk-size [ chunk-extension ] CRLF
                    chunk-data CRLF
   chunk-size     = 1*HEX
   last-chunk     = 1*("0") [ chunk-extension ] CRLF
   chunk-data     = chunk-size(OCTET)

所以你的代码应该是这样的:

print "Content-type: text/plain\r\n";
print "Transfer-Encoding: chunked\r\n";
print "\r\n";
# first chunk
print "10\r\n";
print "0123456789ABCDEF\r\n";
# second chunk
print "10\r\n";
print "0123456789ABCDEF\r\n";
# last chunk
print "0\r\n";
print "\r\n";