mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Fixed decompression for responses without Content-Length header (#5306)
* Fixed decompression for responses without `content-length` header; * Add Brotli encoding to the `Accept-Encoding` header only if it is supported. * `content-length` header transformation moved up; Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
@@ -33,6 +33,7 @@ function setTimeoutAsync(ms) {
|
||||
|
||||
const pipelineAsync = util.promisify(stream.pipeline);
|
||||
const finishedAsync = util.promisify(stream.finished);
|
||||
const gzip = util.promisify(zlib.gzip);
|
||||
|
||||
function toleranceRange(positive, negative) {
|
||||
const p = (1 + 1 / positive);
|
||||
@@ -497,6 +498,23 @@ describe('supports http with nodejs', function () {
|
||||
|
||||
await axios.get(LOCAL_SERVER_URL);
|
||||
});
|
||||
|
||||
it('should not fail if response content-length header is missing', async () => {
|
||||
this.timeout(10000);
|
||||
|
||||
const str = 'zipped';
|
||||
const zipped = await gzip(str);
|
||||
|
||||
server = await startHTTPServer((req, res) => {
|
||||
res.setHeader('Content-Encoding', 'gzip');
|
||||
res.removeHeader('Content-Length');
|
||||
res.end(zipped);
|
||||
});
|
||||
|
||||
const {data} = await axios.get(LOCAL_SERVER_URL);
|
||||
|
||||
assert.strictEqual(data, str);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support UTF8', function (done) {
|
||||
@@ -1411,7 +1429,6 @@ describe('supports http with nodejs', function () {
|
||||
|
||||
it('should omit a user-agent if one is explicitly disclaimed', function (done) {
|
||||
server = http.createServer(function (req, res) {
|
||||
console.log(req.headers);
|
||||
assert.equal("user-agent" in req.headers, false);
|
||||
assert.equal("User-Agent" in req.headers, false);
|
||||
res.end();
|
||||
|
||||
Reference in New Issue
Block a user