2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

Fixed bug #4727 : toFormData Blob issue on node>v17; (#4728)

* Fixed bug #4727;
Added node 18.x to the CI;
Added hotfix for `ERR_OSSL_EVP_UNSUPPORTED` issue with karma running on node >=17.x;
Added `cross-env` to allow running build and test scripts on Windows platforms;

* Added conditional setting of `--openssl-legacy-provider` option for node versions >=17.x;

* Refactored ssl-hotfix & test script;

* Fixed and refactored default max body length test due to ECONNRESET failure;

* Added test for converting the data uri to a Blob;
Fixed bug with parsing mime type for Blob;

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Dmitriy Mozgovoy
2022-05-20 17:31:26 +03:00
committed by GitHub
parent de973f00f3
commit 467025bdb7
8 changed files with 114 additions and 35 deletions
+33 -16
View File
@@ -15,6 +15,9 @@ var formidable = require('formidable');
var express = require('express');
var multer = require('multer');
var bodyParser = require('body-parser');
const isBlobSupported = typeof Blob !== 'undefined';
var noop = ()=> {};
describe('supports http with nodejs', function () {
@@ -572,27 +575,23 @@ describe('supports http with nodejs', function () {
var data = Array(2 * followRedirectsMaxBodyDefaults).join('ж');
server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
res.end();
}).listen(4444, function () {
var success = false, failure = false, error;
// consume the req stream
req.on('data', noop);
// and wait for the end before responding, otherwise an ECONNRESET error will be thrown
req.on('end', ()=> {
res.end('OK');
});
}).listen(4444, function (err) {
if (err) {
return done(err);
}
// send using the default -1 (unlimited axios maxBodyLength)
axios.post('http://localhost:4444/', {
data: data
}).then(function (res) {
success = true;
}).catch(function (err) {
error = err;
failure = true;
});
setTimeout(function () {
assert.equal(success, true, 'request should have succeeded');
assert.equal(failure, false, 'request should not fail');
assert.equal(error, undefined, 'There should not be any error');
assert.equal(res.data, 'OK', 'should handle response');
done();
}, 100);
}).catch(done);
});
});
@@ -1485,6 +1484,24 @@ describe('supports http with nodejs', function () {
}).catch(done);
});
it('should support requesting data URL as a Blob (if supported by the environment)', function (done) {
if (!isBlobSupported) {
this.skip();
return;
}
const buffer = Buffer.from('123');
const dataURI = 'data:application/octet-stream;base64,' + buffer.toString('base64');
axios.get(dataURI, {responseType: 'blob'}).then(async ({data})=> {
assert.strictEqual(data.type, 'application/octet-stream');
assert.deepStrictEqual(await data.text(), '123');
done();
}).catch(done);
});
it('should support requesting data URL as a String (text)', function (done) {
const buffer = Buffer.from('123', 'utf-8');
+1 -1
View File
@@ -7,6 +7,6 @@ describe('helpers::fromDataURI', function () {
const dataURI = 'data:application/octet-stream;base64,' + buffer.toString('base64');
assert.deepStrictEqual(fromDataURI(dataURI), buffer);
assert.deepStrictEqual(fromDataURI(dataURI, false), buffer);
});
});