ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.58k stars 1.33k forks source link

how to send gzip compressed body superagent #1751

Open 0Ams opened 1 year ago

0Ams commented 1 year ago
  it(`should do request with gzip`, async () => {
    const RESPONSE_BODY = { hello: 'world' };
    server.post('/encrypt/body/:id', (_req, res) => res.json(RESPONSE_BODY));
    const data = { test: 'json' };
    const _data = zlib.gzipSync(Buffer.from(JSON.stringify(data)));

    await request
      .post(URI)
      .set('Content-Encoding', 'gzip')
      .set('Content-Type', 'application/json')
      .set('Content-Length', _data.length.toString())
      .set('Accept-Encoding', 'gzip')
      .send(_data);
  });

The test code was written as above. However, an internal error occurs on the server side...

But, When the server code is the same, the test using curl works fine.

echo '{"test":"json"}' | gzip > test_body.gz
curl -v -i -X post http://localhost:8080/gzip -H 'content-encoding: gzip' -H 'content-type: application/json' --data-binary @test_body.gz

I want you to give me a hint to solve this...

(with restify)