mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Add independent maxBodyLength option (#2781)
* Add independent option to set the maximum size of the request body * Remove maxBodyLength check * Update README * Assert for error code and message
This commit is contained in:
@@ -34,6 +34,7 @@ const config: AxiosRequestConfig = {
|
||||
onUploadProgress: (progressEvent: any) => {},
|
||||
onDownloadProgress: (progressEvent: any) => {},
|
||||
maxContentLength: 2000,
|
||||
maxBodyLength: 2000,
|
||||
validateStatus: (status: number) => status >= 200 && status < 300,
|
||||
maxRedirects: 5,
|
||||
proxy: {
|
||||
|
||||
@@ -296,6 +296,37 @@ describe('supports http with nodejs', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support max body length', function (done) {
|
||||
var data = Array(100000).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;
|
||||
|
||||
axios.post('http://localhost:4444/', {
|
||||
data: data
|
||||
}, {
|
||||
maxBodyLength: 2000
|
||||
}).then(function (res) {
|
||||
success = true;
|
||||
}).catch(function (err) {
|
||||
error = err;
|
||||
failure = true;
|
||||
});
|
||||
|
||||
|
||||
setTimeout(function () {
|
||||
assert.equal(success, false, 'request should not succeed');
|
||||
assert.equal(failure, true, 'request should fail');
|
||||
assert.equal(error.code, 'ERR_FR_MAX_BODY_LENGTH_EXCEEDED');
|
||||
assert.equal(error.message, 'Request body larger than maxBodyLength limit');
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should support sockets', function (done) {
|
||||
server = net.createServer(function (socket) {
|
||||
socket.on('data', function () {
|
||||
|
||||
Reference in New Issue
Block a user