Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed import of url module in browser build due to huge size overhead… #4594

Merged
merged 2 commits into from Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/adapters/http.js
Expand Up @@ -17,6 +17,8 @@ var CanceledError = require('../cancel/CanceledError');

var isHttps = /https:?/;

var supportedProtocols = [ 'http:', 'https:', 'file:' ];

/**
*
* @param {http.ClientRequestArgs} options
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 5 additions & 9 deletions lib/adapters/xhr.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -206,16 +203,15 @@ module.exports = function xhrAdapter(config) {
requestData = null;
}

if (parsed.path === null) {
reject(new AxiosError('Malformed URL ' + fullPath, AxiosError.ERR_BAD_REQUEST, config));
return;
}
var tokens = fullPath.split(':', 2);
var protocol = tokens.length > 1 && tokens[0];

if (!utils.supportedProtocols.includes(protocol)) {
reject(new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_BAD_REQUEST, config));
if (protocol && [ 'http', 'https', 'file' ].indexOf(protocol) === -1) {
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
return;
}


// Send the request
request.send(requestData);
});
Expand Down
18 changes: 0 additions & 18 deletions lib/utils.js
Expand Up @@ -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
*
Expand Down Expand Up @@ -453,8 +437,6 @@ var isTypedArray = (function(TypedArray) {
})(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));

module.exports = {
supportedProtocols: supportedProtocols,
getProtocol: getProtocol,
isArray: isArray,
isArrayBuffer: isArrayBuffer,
isBuffer: isBuffer,
Expand Down