我的返回数据没有使用connect.compress()进行gzip压缩 [英] My returned data is not gzipped with connect.compress()
问题描述
我正在尝试使用 connect.compress()
中间件来gzip我对客户端的响应。我可以部分地使用它,但是当我使用 res.end
添加我自己的响应时,响应不再被gzip压缩。
I am trying to use the connect.compress()
middleware to gzip my responses to the client. I am able to partially get it to work but when I add my own response using res.end
the response is no longer gzipped.
Gzipped回复:
Gzipped responses:
app = connect()
.use(connect.compress())
.use(connect.query())
.use(connect.json());
未gzipped回复:
Not gzipped responses:
app = connect()
.use(connect.compress())
.use(connect.query())
.use(connect.json())
.use(function (req, res) {
res.end('hello');
});
我希望能够回复我自己的消息,但仍然有内容gzip 。
推荐答案
我遇到了与小型HTTP响应机构相同的问题。如果响应主体的Content-Length<压缩'阈值(默认为1024字节),然后响应将不压缩,没有警告(参见源代码)。
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).
解决方案是禁用阈值。
app.use(connect.compress({ threshold: false }));
作为Connect的新播放器,我希望API能够记录默认值到位(即:未指定默认为1024字节的阈值。我个人认为不指定阈值应该默认为0;我不想要一个阈值,否则我会在配置中指定它。
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.
这篇关于我的返回数据没有使用connect.compress()进行gzip压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!