0

I have something like:

var app = require('express')();
var compression = require('compression');
app.use(compression());

app.get('/', function(request, response) {
response.send('<!DOCTYPE html>.......');
}
app.listen(2345);

The problem is that the data gets sent chunked but I want it to be wholly sent with a content-length header. Just like Apache does by default (Why I want this behavior is explained in the comments).
So how do I send gzipped data directly and not chunked in express?

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
Core_dumped
  • 1,571
  • 4
  • 16
  • 34
  • It's inefficient to not send your gzipped data chunked. That would require scratch disk space or memory for the whole resource while the compression is occurring, plus the output wouldn't be able to be streamed. Why do you need to do this? I would also suggest leaving this sort of task up to the upstream web server such as Nginx (or even Apache if that's what your preference is). – Brad Feb 17 '15 at 20:01
  • Well the thing is that Weird stuff happens. If I am on <250kbps I get 300ms of latency and 3k of data gets downloaded in a couple of ms. While if I am on >250kbps get less latency as it should be but data gets downloaded in ~200ms no matter whether I am on 750kbps or 30Mbps, always 200ms. if I send this gzipped data using Apache where it sets content length download occurs normally in ~1ms. What is all this about? – Core_dumped Feb 17 '15 at 20:08
  • to be more precise the 3k data gets downloaded in 1ms if I am on 250kbps network, in 100ms if I am on 750kbps network and 200ms when on 30 Mbps. What is this?? As network speed increases download time also increases? Shouldn't they be inversely proportional? This happens if data gets sent chunked. – Core_dumped Feb 17 '15 at 20:17
  • It isn't entirely clear what you are testing. First, isolate the issue and narrow it down to the application by calling your server on `127.0.0.1`. I would also say that 300ms to compress 3KB of data is an extremely long amount of time. I'm not convinced that your problem has anything to do with chunking. Call over localhost and do a packet capture to see. – Brad Feb 17 '15 at 21:44
  • Copy the code as in my question, fill up the request.send with 3k (in my case when compressed it becomes 1.5k) of data and test it on different network speed in DevTools (250kbps, 750kbps, 30Mbps) and you'll see this result. – Core_dumped Feb 17 '15 at 21:47
  • 1
    Don't use your dev tools, that isn't a reliable method of testing at different speeds, especially at such small content sizes. – Brad Feb 17 '15 at 23:02
  • I don't think they are wrong since I can perceive those 200 ms it takes to download with 32Mbps – Core_dumped Feb 17 '15 at 23:06
  • Your assertion is that it has to do with transfer encoding. That's what I'm disputing. – Brad Feb 17 '15 at 23:07
  • I did an additional test and created a question with all the results, check it out: http://stackoverflow.com/questions/28572141/unexpected-behavior-when-increasing-network-speed-and-connecting-to-a-node-js-se?noredirect=1#comment45455809_28572141 – Core_dumped Feb 17 '15 at 23:29

0 Answers0