Socket
Socket
Sign inDemoInstall

ant-http

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ant-http - npm Package Compare versions

Comparing version 1.1.5 to 1.2.0

60

anthttp.js

@@ -12,7 +12,2 @@ const http = require('http');

//设置此消息头,可以覆盖掉默认选项,可以添加
this.headers = {
};
this.mime_map = {

@@ -86,3 +81,3 @@ 'css' : 'text/css',

this.get = function(url, callback) {
this.get = function(url, callback, encoding='utf8') {
var opts = this.parseUrl(url);

@@ -107,7 +102,7 @@ opts.method = 'GET';

res.setEncoding('utf8');
res.setEncoding(encoding);
var get_data = '';
res.on('data', (data) => {
get_data += data.toString();
get_data += data.toString(encoding);
});

@@ -130,4 +125,15 @@

/*
options = {
data,
headers,
encoding
}
*/
this.post = function(url, data, callback) {
this.post = function(url, options, callback) {
if (options.encoding === undefined) {
options.encoding = 'utf8';
}
var opts = this.parseUrl(url);

@@ -140,13 +146,15 @@ var h = (opts.protocol === 'https:') ? https : http;

for(var k in this.headers) {
opts.headers[k] = this.headers[k];
if (options.headers !== undefined) {
for(var k in options.headers) {
opts.headers[k] = this.headers[k];
}
}
if (opts.headers['Content-Type'] === 'application/x-www-form-urlencoded') {
post_data = qs.stringify(data);
post_data = qs.stringify(options.data);
} else {
if (typeof data === 'object') {
post_data = JSON.stringify(data);
if (typeof options.data === 'object') {
post_data = JSON.stringify(options.data);
} else {
post_data = data;
post_data = options.data;
}

@@ -160,5 +168,5 @@ }

res.setEncoding('utf8');
res.setEncoding(options.encoding);
res.on('data', (data) => {
res_data += data.toString();
res_data += data.toString(options.encoding);
});

@@ -245,3 +253,2 @@

}
console.log(formData);
}

@@ -299,2 +306,19 @@

/*
options = {
method : GET | POST,
data : Object (if method == POST)
}
*/
this.download = function(url, options, callback) {
if (options.method == 'GET') {
return this.get(url, callback, 'binary');
} else if (options.method == 'POST') {
return this.post(url, {
data : options.data,
encoding : 'binary'
}, callback);
}
};
};

@@ -301,0 +325,0 @@

{
"name": "ant-http",
"version": "1.1.5",
"version": "1.2.0",
"description": "simple http/https request lib",

@@ -5,0 +5,0 @@ "main": "anthttp.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