【问题标题】:Pipe gzipped content without decompression to response in NodeJS在 NodeJS 中将 gzip 压缩的内容在不解压缩的情况下传递给响应
【发布时间】:2020-11-26 21:33:42
【问题描述】:

我正在使用 node-fetch 库,默认情况下它会解压缩响应。我想发出一个返回 gzip 压缩内容的 POST 请求,并且我想通过管道将 POST 请求响应传递给响应。

我目前使用的代码在这里:

router.post('/getData', async(request, response) => {
fetch(`http://url:port/path`, { method: 'POST', headers: {'Accept-Encoding': 'gzip'}, body: ''})
        .then(data=> {
             return data.body.pipe(response);
         }
    }
}

我了解 node-fetch 库默认解压缩数据。我不需要这个。我想直接使用流传递压缩数据。 (就像一个代理)

【问题讨论】:

    标签: node.js proxy stream gzip


    【解决方案1】:

    对我有用的是设置compress=false,然后添加标头以接受 gzip 编码:

    fetch(url, {
        compress: false,
        headers: { "accept-encoding": "gzip" },
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 1970-01-01
      • 2012-12-02
      相关资源
      最近更新 更多