mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
Returned error treated when requesting uncommon URL (#3544)
* Fixing error returned when requesting illegal URL * Adding unit tests http.js * Fixing error message axios invalid request from browser * Adding unit tests requests.spec.js * Adding at utils.js a new method: getProtocol Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
committed by
GitHub
parent
412d3bd607
commit
195c8e5ff5
@@ -122,7 +122,15 @@ module.exports = function httpAdapter(config) {
|
||||
// Parse url
|
||||
var fullPath = buildFullPath(config.baseURL, config.url);
|
||||
var parsed = url.parse(fullPath);
|
||||
var protocol = parsed.protocol || 'http:';
|
||||
var protocol = utils.getProtocol(parsed.protocol);
|
||||
|
||||
if (parsed.path === null) {
|
||||
return reject(createError('Malformed URL ' + fullPath, config));
|
||||
}
|
||||
|
||||
if (!utils.supportedProtocols.includes(protocol)) {
|
||||
return reject(createError('Unsupported protocol ' + protocol, config));
|
||||
}
|
||||
|
||||
if (!auth && parsed.auth) {
|
||||
var urlAuth = parsed.auth.split(':');
|
||||
|
||||
@@ -8,6 +8,7 @@ var buildFullPath = require('../core/buildFullPath');
|
||||
var parseHeaders = require('./../helpers/parseHeaders');
|
||||
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
||||
var createError = require('../core/createError');
|
||||
var url = require('url');
|
||||
var transitionalDefaults = require('../defaults/transitional');
|
||||
var Cancel = require('../cancel/Cancel');
|
||||
|
||||
@@ -41,6 +42,9 @@ 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);
|
||||
|
||||
// Set the request timeout in MS
|
||||
@@ -206,6 +210,16 @@ module.exports = function xhrAdapter(config) {
|
||||
requestData = null;
|
||||
}
|
||||
|
||||
if (parsed.path === null) {
|
||||
reject(createError('Malformed URL ' + fullPath, config));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!utils.supportedProtocols.includes(protocol)) {
|
||||
reject(createError('Unsupported protocol ' + protocol, config));
|
||||
return;
|
||||
}
|
||||
|
||||
// Send the request
|
||||
request.send(requestData);
|
||||
});
|
||||
|
||||
@@ -6,6 +6,22 @@ var bind = require('./helpers/bind');
|
||||
|
||||
var toString = Object.prototype.toString;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -324,6 +340,8 @@ function stripBOM(content) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
supportedProtocols: supportedProtocols,
|
||||
getProtocol: getProtocol,
|
||||
isArray: isArray,
|
||||
isArrayBuffer: isArrayBuffer,
|
||||
isBuffer: isBuffer,
|
||||
|
||||
Reference in New Issue
Block a user