My returned data is not gzipped with connect.compress()

非 Y 不嫁゛ 提交于 2019-12-05 21:38:23

I had the same problem with small HTTP response bodies. If the Content-Length of the response body < compress' threshold value (default is 1024 bytes), then the response will not be compressed, with no warning (see the source code).

The solution is disable the threshold.

app.use(connect.compress({ threshold: false }));

As a new player to Connect I would expect that APIs would document what default values would be in place (ie: not specifying a threshold value default to 1024 bytes). Personally I think that not specifying a threshold should default it to 0; I don't want a threshold otherwise I'd specify it in the config.

Try replacing this:

res.end('hello');

with this:

res.end(new Buffer('hello', 'utf8'));

If that works, it's probably a bug in your version of the connect middleware.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!