1
我試圖用gzip發送響應塊,但從下面的例子中我在Chrome中得到「Hello S/I m S k 」而是「Hello World!」node.js streaming gzip http responses
var http = require('http'),
zlib = require('zlib');
http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'html/text',
'Transfer-Encoding': 'chunked',
'Content-Encoding': 'gzip',
'Content-Type': 'text/html;charset=UTF-8'
});
zlib.gzip("Hello", function(_, result) {
res.write(result);
});
zlib.gzip(" World", function(_, result) {
res.write(result);
});
zlib.gzip('!', function(_, result) {
res.end(result);
});
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
謝謝,但不知道如何與我描述的問題有關。你能否提供更多細節? –
你對HTTP客戶端說謊,說下面會有分塊編碼,但是不會那麼做。如果你不是按照標準構建HTTP流的話,你不能指望一個好的結果。 –