Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send gzip compressed body #300

Open
richzw opened this issue Jan 10, 2022 · 0 comments
Open

How to send gzip compressed body #300

richzw opened this issue Jan 10, 2022 · 0 comments

Comments

@richzw
Copy link

richzw commented Jan 10, 2022

We want to send compressed body by gzip HTTP request in chai-http in mocha.

let chai = require('chai');
let chaiHttp = require('chai-http');
const zlib = require('zlib');

chai.use(chaiHttp);


object = {
    "content": {
        "data": {
            "key": "testval"
        }
    }
};

const objStr = JSON.stringify(object);
const objBuf = Buffer.from(objStr, "utf-8");
const bodyContent = zlib.gzipSync(objBuf);
const bodyLen = Buffer.byteLength(bodyContent, 'utf-8');

chai.request("http://serverurl")
    .post('/path')
    .set('Content-Type', 'application/json')
    .set('Content-Encoding', 'gzip')
    .set('Content-Length', bodyLen) 
    .set('Accept-Encoding', 'gzip')
    .send(bodyContent)
    .end((err, res) => {
        expect(err).to.be.null;
        expect(res).to.have.status(200);

        done();
    });

However, we met the error Error: incorrect header check at Zlib.zlibOnError on the server-side. Is there anything am I missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant