Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
res.on( 'end', function() {
var buffer = bufferHelper.toBuffer();
try {
var result = self._opt.encoding === ENCODING_RAW
? buffer
: ( self._opt.dataType !== 'json'
? iconv.fromEncoding( buffer, self._opt.encoding )
: JSON.parse( iconv.fromEncoding( buffer, self._opt.encoding ) ) );
} catch ( e ) {
clearTimeout( timer );
errCallback( new Error( "The result has syntax error. " + e ) );
return;
}
clearTimeout( timer );
//get data sucessfully
//add redis cache
var _key = reqObj.proxy._opt.id || "";
console.log("\033[32mfrom request:"+_key+"\033[0m");
reqObj.expire && reqObj.expire>0 && self.addRedisCache(reqObj,result);
callback( result, res.headers['set-cookie'] );
res.on( 'end', function() {
var buffer = bufferHelper.toBuffer();
try {
var result = self._opt.encoding === ENCODING_RAW
? buffer
: ( self._opt.dataType !== 'json'
? iconv.fromEncoding( buffer, self._opt.encoding )
: JSON.parse( iconv.fromEncoding( buffer, self._opt.encoding ) ) );
} catch ( e ) {
clearTimeout( timer );
errCallback( new Error( "The result has syntax error. " + e ) );
return;
}
clearTimeout( timer );
//get data sucessfully
//add redis cache
var _key = reqObj.proxy._opt.id || "";
console.log("\033[32mfrom request:"+_key+"\033[0m");
reqObj.expire && reqObj.expire>0 && self.addRedisCache(reqObj,result);
function readFileSync(filePath, encoding) {
var buffer = new Buffer('');
try {
buffer = Fs.readFileSync(filePath);
} catch (e) {
error(e.toString());
}
if (!encoding) {
return buffer;
}
var fileStr = Iconv.fromEncoding(buffer, encoding);
return fileStr;
}
res2.on( 'end', function() {
var buffer = bufferHelper.toBuffer();
var result;
try {
result = self._opt.encoding === ENCODING_RAW
? buffer
: iconv.fromEncoding( buffer, self._opt.encoding );
} catch ( e ) {
res.statusCode = 500;
res.end( e + '' );
return;
}
res.setHeader( 'Set-Cookie', res2.headers['set-cookie'] );
res.setHeader( 'Content-Type'
, ( self._opt.dataType === 'json' ? 'application/json' : 'text/html' )
+ ';charset=UTF-8' );
res.end( result );
} );
} );
var buffer = Buffer.concat(source, size);
if (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 202) {
var e = new Error('Response error. rid = ' + rid
+ ', interfaceId = ' + self._opt.id
+ ', url = ' + self._opt.currUrl
+ ', statusCode = ' + res.statusCode);
e.statusCode = res.statusCode;
e.responseText = buffer.toString();
( isCompleted = true ) && errCallback(e);
return;
}
try {
var result = self._opt.encoding === Constant.ENCODING_RAW
? buffer
: ( self._opt.dataType !== Constant.JSON && self._opt.dataType !== Constant.JSONP
? iconv.fromEncoding(buffer, self._opt.encoding)
: JSON.parse(iconv.fromEncoding(buffer, self._opt.encoding)) );
} catch (e) {
errCallback(new Error('The result has syntax error. interfaceId = '
+ self._opt.id + ', url = ' + self._opt.currUrl + '. Caused By: ' + e.message));
return;
}
isCompleted || callback(result, res.headers['set-cookie']);
isCompleted = true;
});
if (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 202) {
var e = new Error('Response error. rid = ' + rid
+ ', interfaceId = ' + self._opt.id
+ ', url = ' + self._opt.currUrl
+ ', statusCode = ' + res.statusCode);
e.statusCode = res.statusCode;
e.responseText = buffer.toString();
( isCompleted = true ) && errCallback(e);
return;
}
try {
var result = self._opt.encoding === Constant.ENCODING_RAW
? buffer
: ( self._opt.dataType !== Constant.JSON && self._opt.dataType !== Constant.JSONP
? iconv.fromEncoding(buffer, self._opt.encoding)
: JSON.parse(iconv.fromEncoding(buffer, self._opt.encoding)) );
} catch (e) {
errCallback(new Error('The result has syntax error. interfaceId = '
+ self._opt.id + ', url = ' + self._opt.currUrl + '. Caused By: ' + e.message));
return;
}
isCompleted || callback(result, res.headers['set-cookie']);
isCompleted = true;
});
res2.on('end', function () {
var buffer = Buffer.concat(source, size);
var result;
try {
result = self._opt.encoding === Constant.ENCODING_RAW
? buffer
: iconv.fromEncoding(buffer, self._opt.encoding);
} catch (e) {
res.statusCode = 500;
res.end(e + '');
return;
}
res.setHeader('Set-Cookie', res2.headers['set-cookie']);
res.statusCode = res2.statusCode;
res.setHeader('Content-Type', res2.headers['Content-Type']);
res.end(result);
});
res2.on('error', function (err) {