New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-ral

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-ral - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

lib/ext/converter/formConverter.js

19

lib/config.js

@@ -37,2 +37,3 @@ /**

* regularly update config with config nomalizer
*
* @param {number} interval [description]

@@ -47,6 +48,4 @@ * @param {boolean} all [description]

}
// 对齐至每分钟开始时启动更新,使多个cluster之间保持大致同步
var padding = 59 - (new Date()).getSeconds();
setTimeout(function () {
function start() {
updateInterval = setInterval(function () {

@@ -66,2 +65,9 @@ configUpdater.update(function (err, confs) {

}, interval);
}
// 对齐至每分钟开始时启动更新,使多个cluster之间保持大致同步
var padding = 59 - (new Date()).getSeconds();
setTimeout(function () {
start();
}, padding * 1000);

@@ -83,2 +89,3 @@ };

* load rawConf to valid conf
*
* @param {Object} inputRawConf [description]

@@ -88,4 +95,6 @@ * @return {Object} [description]

function loadRawConf(inputRawConf) {
/**
* validate
*
* @param {string} serviceID [description]

@@ -150,2 +159,3 @@ * @param {Object} serviceInfo [description]

* load config by config folder
*
* @param {string} confPath [description]

@@ -215,2 +225,3 @@ * @return {Object} [description]

* get runtime config context
*
* @param {string} serviceID [description]

@@ -269,2 +280,3 @@ * @param {Object} options [description]

* get all service keys
*
* @return {Array} service keys

@@ -278,2 +290,3 @@ */

* get raw conf
*
* @return {Object} raw conf

@@ -280,0 +293,0 @@ */

3

lib/config/configNormalizer.js

@@ -21,3 +21,4 @@ /**

* normalize config
* @param {Object} config [description]
*
* @param {Object} config [service config]
*/

@@ -24,0 +25,0 @@ ConfigNormalizer.prototype.normalizeConfig = function (config) {

@@ -25,5 +25,5 @@ /**

* Config Updater
* used to update config with ConfigNormalizer
*
* used to update config with ConfigNormalizer
* @param {Object} options [description]
* @param {Object} options [service config]
*/

@@ -54,2 +54,3 @@ function Updater(options) {

* check whether the update is done
*
* @param {Function} cb [description]

@@ -98,2 +99,3 @@ */

* run interval update
*
* @param {Function} cb [description]

@@ -100,0 +102,0 @@ * @param {boolean} all [description]

@@ -7,4 +7,5 @@ /**

*/
/*eslint-env node, mocha */
/* eslint-env node, mocha */
'use strict';

@@ -11,0 +12,0 @@

@@ -5,56 +5,7 @@ /**

* http://fis.baidu.com/
* 2014/8/7
* 2016/01/11
*
* This is a empty file to fix typo
*/
'use strict';
var Converter = require('../../converter.js');
var logger = require('../../logger.js')('FormConverter');
var util = require('util');
var urlencode = require('urlencode');
function FormConverter() {
Converter.call(this);
}
util.inherits(FormConverter, Converter);
FormConverter.prototype.unpack = function (config, data) {
try {
var object = urlencode.parse(data.toString(), {
charset: config.encoding
});
logger.trace('unpack urlencode data succ ServiceID=' + config.serviceID);
return object;
}
catch (ex) {
logger.trace('unpack urlencode data failed ServiceID=' + config.serviceID);
throw ex;
}
};
FormConverter.prototype.pack = function (config, data) {
data = data || {};
var buffer;
try {
buffer = urlencode.stringify(data, {
charset: config.encoding
});
}
catch (e) {
logger.trace('pack urlencode data failed data=' + data + ' ServiceID=' + config.serviceID);
throw e;
}
config.headers = config.headers || {};
var encoding = config.encoding ? config.encoding : 'utf-8';
config.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=' + encoding;
config.headers['Content-Length'] = buffer.length;
logger.trace('pack urlencode data succ ServiceID=' + config.serviceID + ' data=' + buffer);
return buffer;
};
FormConverter.prototype.getName = function () {
return 'form';
};
module.exports = FormConverter;
module.exports = {};

@@ -11,3 +11,3 @@ /**

var Converter = require('../../converter.js');
var FormConverter = require('./fromConverter.js');
var FormConverter = require('./formConverter.js');
var logger = require('../../logger.js')('QuertStringConverter');

@@ -14,0 +14,0 @@ var util = require('util');

@@ -11,3 +11,3 @@ /**

var Protocol = require('./httpProtocolBase.js');
var logger = require('../../logger.js')('HttpProtocol');
// var logger = require('../../logger.js')('HttpProtocol');
var util = require('util');

@@ -14,0 +14,0 @@

@@ -18,2 +18,3 @@ /**

var url = require('url');
var ctx = require('../../ctx.js');

@@ -40,5 +41,31 @@ function HttpProtocolBase() {

}
if (config.path && config.path[0] !== '/') {
config.path = '/' + config.path;
if (config.path) {
// auto replace spaces in path
config.path = config.path.replace(/ /g, '%20');
if (config.path[0] !== '/') {
config.path = '/' + config.path;
}
}
// support idc proxy
if (config.proxy && config.proxy instanceof Array) {
var defaultProxy = null;
var idcProxyFounded = false;
for (var i = 0; i < config.proxy.length; i++) {
var proxy = config.proxy[i];
if (proxy.idc === 'default') {
defaultProxy = proxy.uri;
}
if (proxy.idc === ctx.currentIDC) {
idcProxyFounded = true;
config.proxy = proxy.uri;
break;
}
}
if (defaultProxy && !idcProxyFounded) {
config.proxy = defaultProxy;
}
if (!defaultProxy && !idcProxyFounded && config.proxy[0]) {
config.proxy = config.proxy[0].uri;
}
}
return config;

@@ -115,3 +142,3 @@ };

opt.headers = opt.headers || {};
opt.headers['HOST'] = opt.host + ':' + opt.port;
opt.headers.HOST = opt.host + ':' + opt.port;
opt.path = url.resolve(uri, path);

@@ -133,11 +160,11 @@ var proxyUri = url.parse(proxy);

// or, just use zlib.createUnzip() to handle both cases
case 'gzip':
res.pipe(zlib.createGunzip()).pipe(response);
break;
case 'deflate':
res.pipe(zlib.createInflate()).pipe(response);
break;
default:
res.pipe(response);
break;
case 'gzip':
res.pipe(zlib.createGunzip()).pipe(response);
break;
case 'deflate':
res.pipe(zlib.createInflate()).pipe(response);
break;
default:
res.pipe(response);
break;
}

@@ -144,0 +171,0 @@ callback && callback(response);

@@ -11,3 +11,3 @@ /**

var Protocol = require('./httpProtocolBase.js');
var logger = require('../../logger.js')('HttpsProtocol');
// var logger = require('../../logger.js')('HttpsProtocol');
var util = require('util');

@@ -14,0 +14,0 @@

@@ -6,3 +6,3 @@ /**

'use strict'
'use strict';

@@ -15,3 +15,3 @@ function formatHostname(hostname) {

function parseNoProxyZone(zone) {
zone = zone.trim().toLowerCase()
zone = zone.trim().toLowerCase();

@@ -39,4 +39,4 @@ var zoneParts = zone.split(':', 2);

var hostnameMatched = (
isMatchedAt > -1 &&
(isMatchedAt === hostname.length - noProxyZone.hostname.length)
isMatchedAt > -1
&& (isMatchedAt === hostname.length - noProxyZone.hostname.length)
);

@@ -49,3 +49,3 @@

return hostnameMatched;
})
});
}

@@ -75,11 +75,8 @@

if (uri.protocol === 'http:') {
return process.env.HTTP_PROXY ||
process.env.http_proxy || null;
return process.env.HTTP_PROXY || process.env.http_proxy || null;
}
if (uri.protocol === 'https:') {
return process.env.HTTPS_PROXY ||
process.env.https_proxy ||
process.env.HTTP_PROXY ||
process.env.http_proxy || null;
return process.env.HTTPS_PROXY || process.env.https_proxy
|| process.env.HTTP_PROXY || process.env.http_proxy || null;
}

@@ -86,0 +83,0 @@

@@ -8,3 +8,3 @@ /**

/*eslint-disable fecs-camelcase, camelcase */
/* eslint-disable fecs-camelcase, camelcase */

@@ -11,0 +11,0 @@ 'use strict';

@@ -8,3 +8,3 @@ /**

/*eslint-disable fecs-camelcase, camelcase */
/* eslint-disable fecs-camelcase, camelcase */

@@ -19,3 +19,3 @@ 'use strict';

var RalModule = require('./ralmodule.js');
var iconv = require('iconv-lite');
// var iconv = require('iconv-lite');
var EventEmitter = require('events').EventEmitter;

@@ -22,0 +22,0 @@ var now = require('performance-now');

@@ -46,3 +46,5 @@ /**

var ModuleClass = require(filePath);
loadModule(new ModuleClass());
if (ModuleClass && typeof ModuleClass === 'function') {
loadModule(new ModuleClass());
}
}

@@ -49,0 +51,0 @@ }

@@ -32,2 +32,3 @@ /**

* aware of DateTime won't be parse well when using this method
*
* @param {Object} object [description]

@@ -34,0 +35,0 @@ * @return {Object} [description]

{
"name": "node-ral",
"version": "0.4.1",
"version": "0.5.0",
"description": "a rpc client for node",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -19,3 +19,3 @@ /**

var HttpProtocol = require('../lib/ext/protocol/httpProtocol.js');
var FormConverter = require('../lib/ext/converter/fromConverter.js');
var FormConverter = require('../lib/ext/converter/formConverter.js');
var QueryStringConverter = require('../lib/ext/converter/querystringConverter.js');

@@ -22,0 +22,0 @@ var RawConverter = require('../lib/ext/converter/rawConverter.js');

@@ -18,2 +18,3 @@ /**

var util = require('../lib/util.js');
var CTX = require('../lib/ctx.js');

@@ -53,2 +54,87 @@ var mockHTTPService = {

var mockHTTPService4 = {
timeout: 1000,
path: 'path/to/ service',
method: 'POST',
query: 'a=1',
headers: {
'User-Agent': 'Chrome'
}
};
var mockProxyService = {
timeout: 1000,
path: 'path/to/service',
method: 'POST',
query: 'a=1',
headers: {
'User-Agent': 'Chrome'
},
proxy: [
{
uri: 'http://127.0.0.1:8083',
idc: 'jx'
},
{
uri: 'http://127.0.0.1:8084',
idc: 'tc'
},
{
uri: 'http://127.0.0.1:8085',
idc: 'default'
}
]
};
var mockProxyService2 = {
timeout: 1000,
path: 'path/to/service',
method: 'POST',
query: 'a=1',
headers: {
'User-Agent': 'Chrome'
},
proxy: [
{
uri: 'http://127.0.0.1:8085',
idc: 'default'
},
{
uri: 'http://127.0.0.1:8084',
idc: 'tc'
}
]
};
var mockProxyService3 = {
timeout: 1000,
path: 'path/to/service',
method: 'POST',
query: 'a=1',
headers: {
'User-Agent': 'Chrome'
},
proxy: 'http://127.0.0.1:8085'
};
var mockProxyService4 = {
timeout: 1000,
path: 'path/to/service',
method: 'POST',
query: 'a=1',
headers: {
'User-Agent': 'Chrome'
},
proxy: [
{
uri: 'http://127.0.0.1:8088',
idc: 'jx-fake'
},
{
uri: 'http://127.0.0.1:8084',
idc: 'tc'
}
]
};
describe('protocol', function () {

@@ -80,2 +166,3 @@ it('should fail when get name', function () {

describe('http protocol with get method', function () {
it('should work fine with GET method', function (done) {

@@ -313,4 +400,44 @@ var getTest = require('./protocol/http_protocol_get_test.js');

});
it('should fix path when contains spaces', function () {
var context = HttpProtocol.normalizeConfig(mockHTTPService4);
context.path.should.be.eql('/path/to/%20service');
});
});
describe('http proxy', function () {
it('should get correct idc proxy config', function () {
var originIDC = CTX.currentIDC;
CTX.currentIDC = 'jx';
var context = HttpProtocol.normalizeConfig(mockProxyService);
context.proxy.should.be.equal('http://127.0.0.1:8083');
CTX.currentIDC = originIDC;
});
it('should get default proxy when idc is not match', function () {
var originIDC = CTX.currentIDC;
CTX.currentIDC = 'jx';
var context = HttpProtocol.normalizeConfig(mockProxyService2);
context.proxy.should.be.equal('http://127.0.0.1:8085');
CTX.currentIDC = originIDC;
});
it('should get proxy when none idc is set', function () {
var originIDC = CTX.currentIDC;
CTX.currentIDC = 'jx';
var context = HttpProtocol.normalizeConfig(mockProxyService3);
context.proxy.should.be.equal('http://127.0.0.1:8085');
CTX.currentIDC = originIDC;
});
it('should get first proxy when idc proxy is not found and no default proxy', function () {
var originIDC = CTX.currentIDC;
CTX.currentIDC = 'jx';
var context = HttpProtocol.normalizeConfig(mockProxyService4);
context.proxy.should.be.equal('http://127.0.0.1:8088');
CTX.currentIDC = originIDC;
});
});
describe('soap protocol', function () {

@@ -317,0 +444,0 @@ it.skip('should request wsdl service successfully', function (done) {

@@ -621,2 +621,17 @@ /**

});
it.skip('should catch sync error with http', function (done) {
before(function (ok) {
isInited.on('done', ok);
});
var req = ral('GET_QS_SERV', {
path: '/cl ose',
timeout: 200,
degrade: false
});
req.on('error', function (error) {
error.toString().should.be.match(/Error/);
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc