Socket
Socket
Sign inDemoInstall

yu-node

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yu-node - npm Package Compare versions

Comparing version 1.0.9 to 1.1.0

28

lib/request.js
const node_url = require('url');
const { getType } = require('yu-util');
const querystring = require('querystring');
module.exports = (url,options)=>{
options = getType(options)==='Object' ? options : {};
options.method = options.method || 'get';
options.headers = getType(options.headers)==='Object' ? options.headers: {};
options.method = options.method || 'GET';
options.data = getType(options.data)==='Object' ? options.data : {};
let data = querystring.stringify(options.data);
let headers = {}, postData = '';
if(/post/i.test(options.method)){
postData = data;
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
};
}else{
data.length>0 && (url += '?'+data);
}
let obj = node_url.parse(url);
let { protocol,hostname,port,path } = obj;
const { request,Agent } = protocol.includes('https') ? require('https') : require('http');

@@ -21,3 +31,3 @@ return new Promise(result=>{

path,
headers: options.headers,
headers,
agent:new Agent({ maxSockets:10 })

@@ -30,12 +40,8 @@ },res=>{

res.on('end',()=>{
result({ statusCode:res.statusCode, headers:res.headers, data:buf });
result({ statusCode:res.statusCode, headers:res.headers, data:buf.toString() });
});
});
let dataArr = [];
Object.keys(options.data).forEach(key=>{
dataArr.push(key+'='+data[key]);
});
req.write(dataArr.join('&'));
req.write(postData);
req.end();
});
}
{
"name": "yu-node",
"version": "1.0.9",
"version": "1.1.0",
"description": "仅用于node.js",

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

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