2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-05 16:42:32 +03:00

Using more strict eslint rules

This commit is contained in:
Matt Zabriskie
2015-12-14 20:06:57 -07:00
parent 2b147fb0b7
commit f28a4a8248
16 changed files with 230 additions and 93 deletions
+18 -18
View File
@@ -68,35 +68,35 @@ module.exports = function httpAdapter(resolve, reject, config) {
// Create the request
var transport = parsed.protocol === 'https:' ? https : http;
var req = transport.request(options, function (res) {
var req = transport.request(options, function handleResponse(res) {
// uncompress the response body transparently if required
var stream = res;
switch(res.headers['content-encoding']) {
case 'gzip':
case 'compress':
case 'deflate': {
// add the unzipper to the body stream processing pipeline
stream = stream.pipe(zlib.createUnzip());
switch (res.headers['content-encoding']) {
/*eslint default-case:0*/
case 'gzip':
case 'compress':
case 'deflate':
// add the unzipper to the body stream processing pipeline
stream = stream.pipe(zlib.createUnzip());
// remove the content-encoding in order to not confuse downstream operations
delete res.headers['content-encoding'];
}
// remove the content-encoding in order to not confuse downstream operations
delete res.headers['content-encoding'];
break;
}
var responseBuffer = [];
stream.on('data', function (chunk) {
stream.on('data', function handleStreamData(chunk) {
responseBuffer.push(chunk);
});
stream.on('end', function () {
var data = Buffer.concat(responseBuffer);
stream.on('end', function handleStreamEnd() {
var d = Buffer.concat(responseBuffer);
if (config.responseType !== 'arraybuffer') {
data = data.toString('utf8');
d = d.toString('utf8');
}
var response = {
data: transformData(
data,
d,
res.headers,
config.transformResponse
),
@@ -114,12 +114,12 @@ module.exports = function httpAdapter(resolve, reject, config) {
});
// Handle errors
req.on('error', function (err) {
req.on('error', function handleRequestError(err) {
reject(err);
});
// Handle request timeout
req.setTimeout(config.timeout, function () {
req.setTimeout(config.timeout, function handleRequestTimeout() {
req.abort();
});
+10 -11
View File
@@ -29,13 +29,13 @@ module.exports = function xhrAdapter(resolve, reject, config) {
delete requestHeaders['Content-Type']; // Let the browser set it
}
var adapter = (XMLHttpRequest || ActiveXObject);
var Adapter = (XMLHttpRequest || ActiveXObject);
var loadEvent = 'onreadystatechange';
var xDomain = false;
// For IE 8/9 CORS support
if(!isURLSameOrigin(config.url) && window.XDomainRequest){
adapter = window.XDomainRequest;
if (!isURLSameOrigin(config.url) && window.XDomainRequest) {
Adapter = window.XDomainRequest;
loadEvent = 'onload';
xDomain = true;
}
@@ -44,18 +44,18 @@ module.exports = function xhrAdapter(resolve, reject, config) {
if (config.auth) {
var username = config.auth.username || '';
var password = config.auth.password || '';
requestHeaders['Authorization'] = 'Basic ' + btoa(username + ':' + password);
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
}
// Create the request
var request = new adapter('Microsoft.XMLHTTP');
var request = new Adapter('Microsoft.XMLHTTP');
request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true);
// Set the request timeout in MS
request.timeout = config.timeout;
// Listen for ready state
request[loadEvent] = function () {
request[loadEvent] = function handleReadyState() {
if (request && (request.readyState === 4 || xDomain)) {
// Prepare the response
var responseHeaders = xDomain ? null : parseHeaders(request.getAllResponseHeaders());
@@ -99,13 +99,12 @@ module.exports = function xhrAdapter(resolve, reject, config) {
// Add headers to the request
if (!xDomain) {
utils.forEach(requestHeaders, function (val, key) {
// Remove Content-Type if data is undefined
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
if (!data && key.toLowerCase() === 'content-type') {
// Remove Content-Type if data is undefined
delete requestHeaders[key];
}
// Otherwise add header to the request
else {
} else {
// Otherwise add header to the request
request.setRequestHeader(key, val);
}
});