2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00: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:
Dmitriy Mozgovoy
2022-04-26 10:08:49 +03:00
committed by GitHub
parent cdd7add9b0
commit 4f7e3e3a7a
6 changed files with 849 additions and 717 deletions
+4 -2
View File
@@ -17,6 +17,8 @@ var CanceledError = require('../cancel/CanceledError');
var isHttps = /https:?/;
var supportedProtocols = [ 'http:', 'https:', 'file:' ];
/**
*
* @param {http.ClientRequestArgs} options
@@ -129,9 +131,9 @@ module.exports = function httpAdapter(config) {
// Parse url
var fullPath = buildFullPath(config.baseURL, config.url);
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(
'Unsupported protocol ' + protocol,
AxiosError.ERR_BAD_REQUEST,
+5 -9
View File
@@ -7,7 +7,6 @@ var buildURL = require('./../helpers/buildURL');
var buildFullPath = require('../core/buildFullPath');
var parseHeaders = require('./../helpers/parseHeaders');
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
var url = require('url');
var transitionalDefaults = require('../defaults/transitional');
var AxiosError = require('../core/AxiosError');
var CanceledError = require('../cancel/CanceledError');
@@ -38,8 +37,6 @@ module.exports = function xhrAdapter(config) {
}
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);
@@ -206,15 +203,14 @@ module.exports = function xhrAdapter(config) {
requestData = null;
}
if (parsed.path === null) {
reject(new AxiosError('Malformed URL ' + fullPath, AxiosError.ERR_BAD_REQUEST, config));
var tokens = fullPath.split(':', 2);
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;
}
if (!utils.supportedProtocols.includes(protocol)) {
reject(new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_BAD_REQUEST, config));
return;
}
// Send the request
request.send(requestData);