mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
Removed import of url module in browser build due to significant size overhead; (#4594)
Removed pointless `Malformed URL` checking in client build;
This commit is contained in:
@@ -17,6 +17,8 @@ var CanceledError = require('../cancel/CanceledError');
|
|||||||
|
|
||||||
var isHttps = /https:?/;
|
var isHttps = /https:?/;
|
||||||
|
|
||||||
|
var supportedProtocols = [ 'http:', 'https:', 'file:' ];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {http.ClientRequestArgs} options
|
* @param {http.ClientRequestArgs} options
|
||||||
@@ -129,9 +131,9 @@ module.exports = function httpAdapter(config) {
|
|||||||
// Parse url
|
// Parse url
|
||||||
var fullPath = buildFullPath(config.baseURL, config.url);
|
var fullPath = buildFullPath(config.baseURL, config.url);
|
||||||
var parsed = url.parse(fullPath);
|
var parsed = url.parse(fullPath);
|
||||||
var protocol = utils.getProtocol(parsed.protocol);
|
var protocol = parsed.protocol || supportedProtocols[0];
|
||||||
|
|
||||||
if (!utils.supportedProtocols.includes(protocol)) {
|
if (supportedProtocols.indexOf(protocol) === -1) {
|
||||||
return reject(new AxiosError(
|
return reject(new AxiosError(
|
||||||
'Unsupported protocol ' + protocol,
|
'Unsupported protocol ' + protocol,
|
||||||
AxiosError.ERR_BAD_REQUEST,
|
AxiosError.ERR_BAD_REQUEST,
|
||||||
|
|||||||
+5
-9
@@ -7,7 +7,6 @@ var buildURL = require('./../helpers/buildURL');
|
|||||||
var buildFullPath = require('../core/buildFullPath');
|
var buildFullPath = require('../core/buildFullPath');
|
||||||
var parseHeaders = require('./../helpers/parseHeaders');
|
var parseHeaders = require('./../helpers/parseHeaders');
|
||||||
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
||||||
var url = require('url');
|
|
||||||
var transitionalDefaults = require('../defaults/transitional');
|
var transitionalDefaults = require('../defaults/transitional');
|
||||||
var AxiosError = require('../core/AxiosError');
|
var AxiosError = require('../core/AxiosError');
|
||||||
var CanceledError = require('../cancel/CanceledError');
|
var CanceledError = require('../cancel/CanceledError');
|
||||||
@@ -38,8 +37,6 @@ module.exports = function xhrAdapter(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fullPath = buildFullPath(config.baseURL, config.url);
|
var fullPath = buildFullPath(config.baseURL, config.url);
|
||||||
var parsed = url.parse(fullPath);
|
|
||||||
var protocol = utils.getProtocol(parsed.protocol);
|
|
||||||
|
|
||||||
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
||||||
|
|
||||||
@@ -206,15 +203,14 @@ module.exports = function xhrAdapter(config) {
|
|||||||
requestData = null;
|
requestData = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsed.path === null) {
|
var tokens = fullPath.split(':', 2);
|
||||||
reject(new AxiosError('Malformed URL ' + fullPath, AxiosError.ERR_BAD_REQUEST, config));
|
var protocol = tokens.length > 1 && tokens[0];
|
||||||
|
|
||||||
|
if (protocol && [ 'http', 'https', 'file' ].indexOf(protocol) === -1) {
|
||||||
|
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!utils.supportedProtocols.includes(protocol)) {
|
|
||||||
reject(new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_BAD_REQUEST, config));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the request
|
// Send the request
|
||||||
request.send(requestData);
|
request.send(requestData);
|
||||||
|
|||||||
@@ -22,22 +22,6 @@ function kindOfTest(type) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Array with axios supported protocols.
|
|
||||||
*/
|
|
||||||
var supportedProtocols = [ 'http:', 'https:', 'file:' ];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns URL protocol passed as param if is not undefined or null,
|
|
||||||
* otherwise just returns 'http:'
|
|
||||||
*
|
|
||||||
* @param {String} protocol The String value of URL protocol
|
|
||||||
* @returns {String} Protocol if the value is not undefined or null
|
|
||||||
*/
|
|
||||||
function getProtocol(protocol) {
|
|
||||||
return protocol || 'http:';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a value is an Array
|
* Determine if a value is an Array
|
||||||
*
|
*
|
||||||
@@ -453,8 +437,6 @@ var isTypedArray = (function(TypedArray) {
|
|||||||
})(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
|
})(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
supportedProtocols: supportedProtocols,
|
|
||||||
getProtocol: getProtocol,
|
|
||||||
isArray: isArray,
|
isArray: isArray,
|
||||||
isArrayBuffer: isArrayBuffer,
|
isArrayBuffer: isArrayBuffer,
|
||||||
isBuffer: isBuffer,
|
isBuffer: isBuffer,
|
||||||
|
|||||||
Generated
+833
-675
File diff suppressed because it is too large
Load Diff
@@ -78,6 +78,7 @@
|
|||||||
"unpkg": "dist/axios.min.js",
|
"unpkg": "dist/axios.min.js",
|
||||||
"typings": "./index.d.ts",
|
"typings": "./index.d.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"eslint-g": "^1.3.4",
|
||||||
"follow-redirects": "^1.14.9",
|
"follow-redirects": "^1.14.9",
|
||||||
"form-data": "^4.0.0"
|
"form-data": "^4.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -515,19 +515,12 @@ describe('requests', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return malformed url error message', function (done) {
|
it('should return unsupported protocol error message', function () {
|
||||||
axios.get('tel:484-695-3408')
|
return axios.get('ftp:localhost')
|
||||||
.catch(function (error) {
|
.then(function(){
|
||||||
expect(error.message).toEqual('Malformed URL tel:484-695-3408')
|
fail('Does not throw');
|
||||||
done();
|
}, function (error) {
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return unsupported protocol error message', function (done) {
|
|
||||||
axios.get('ftp:google.com')
|
|
||||||
.catch(function (error) {
|
|
||||||
expect(error.message).toEqual('Unsupported protocol ftp:')
|
expect(error.message).toEqual('Unsupported protocol ftp:')
|
||||||
done();
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user