【发布时间】:2017-06-19 04:51:46
【问题描述】:
这是我嵌入 koa-compress 中间件的代码
app.use(compress({
filter: function (content_type) {
return /text/i.test(content_type)
},
threshold: 1,
flush: require('zlib').Z_SYNC_FLUSH
}))
以下是我的响应发送代码
ctx.body = 'Hello world'
ctx.compress = true
ctx.set('Content-Type', 'text/plain')
ctx.set('content-encoding', 'gzip')
当我通过 CURL 访问 URL 时,我得到一个简单的纯文本,上面写着“Hello World”,但我相信我应该得到一个压缩字符串,因为 CURL 默认情况下不进行解压缩。当我在 ChromeBrowser 上点击相同的 URL 时,我收到错误消息 ERR_CONTENT_DECODING_FAILED
当我将内容编码设置为 gzip 时,koa-compress 应该已经压缩了我的响应文本,但不知何故它没有这样做。也许我犯了一些错误,但我不知道是什么?
【问题讨论】: