HTTP - how to send multiple pre-cached gzipped chunks?

Suppose I have 2 separate gziped html chunks in memory. Can I send chunk1 + chunk2 to an HTTP client? Does any browser support this? Or is there no way to do this, and should I gzip the entire stream not in separate pieces?

I want to serve clients like chunk1 + chunk2 and chunk2 + chunk1 etc. (different order), but I don’t want to compress the whole page every time, and I don’t want to cache the whole page. I want to use pre-compressed cached chunks and send them.

nodejs code (node ​​v0.10.7):

// creating pre cached data buffers var zlib = require('zlib'); var chunk1, chunk2; zlib.gzip(new Buffer('test1'), function(err, data){ chunk1 = data; }); zlib.gzip(new Buffer('test2'), function(err, data){ chunk2 = data; }); var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain', 'Content-Encoding': 'gzip'}); // writing two pre gziped buffers res.write(chunk1); // if I send only this one everything is OK res.write(chunk2); // if I send two chunks Chrome trying to download file res.end(); }).listen(8080); 

When my sample server returns this response in the download window of the Chrome browser browser (it does not understand it: /

+4
source share
2 answers

I have not tried, but if the http clients are compliant with RFC 1952 , then they should accept the gzip concatenated streams and decompress them with the same result, as if all the data were compressed into one stream. The HTTP 1.1 standard in RFC 2616 does apply to RFC 1952.

If in the "fragments" section you refer to encoding with encoding, then this does not depend on compression. If clients accept concatenated streams, then there is no reason for encoded transmission boundaries to be negotiated with gzip streams inside.

As for how to do this, just gzip your parts and directly concatenate them. No other formatting or preparation is required.

+4
source

Also interested in this stuff .. Does anyone know how to pre-cache and then concat gzipped buffers? Chrome shows broken test after first success ...

0
source

Source: https://habr.com/ru/post/1482609/


All Articles