Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import urlencode from 'urlencode';
urlencode('苏千'); // default is utf8
urlencode('苏千', 'gbk'); // '%CB%D5%C7%A7'
// decode gbk
urlencode.decode('%CB%D5%C7%A7', 'gbk'); // '苏千'
// parse gbk querystring
urlencode.parse('nick=%CB%D5%C7%A7', {charset: 'gbk'}); // {nick: '苏千'}
// stringify obj with gbk encoding
const str = 'x[y][0][v][w]=' + urlencode('雾空', 'gbk'); // x[y][0][v][w]=%CE%ED%BF%D5
const obj = {x: {y : [{v : {w : '雾空'}}]}};
urlencode.stringify(obj, {charset: 'gbk'});
HttpProtocolBase.prototype.normalizeConfig = HttpProtocolBase.normalizeConfig = function(config) {
config = Protocol.normalizeConfig(config);
if (config.disableGzip === undefined) {
config.disableGzip = true;
}
if (typeof config.query !== 'object') {
config.query = urlencode.parse(config.query, {
charset: config.encoding
});
}
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];
'Content-Type': 'application/json'
});
if (request.method === 'POST') {
var formIn = new formidable.IncomingForm();
formIn.encoding = encoding || 'utf-8';
formIn.parse(request, function(err, fields) {
response.write(JSON.stringify({
port: port,
query: fields
}));
response.end();
});
} else {
response.write(JSON.stringify({
port: port,
query: urlencode.parse(info.query)
}));
response.end();
}
}
}).listen(port);
};