Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

httpreq

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httpreq - npm Package Compare versions

Comparing version 0.2.7 to 0.2.8

28

examples.js

@@ -118,2 +118,30 @@ var httpreq = require('./httpreq');

// set max redirects:
httpreq.get('http://scobleizer.com/feed/',{
maxRedirects: 2, // default is 10
headers:{
'User-Agent': 'Magnet', //for some reason causes endless redirects on this site...
}},
function (err, res) {
if (err){
console.log(err);
}else{
console.log(res.body);
}
}
);
// set timeout
httpreq.get('http://localhost:3000/',{
timeout: (5 * 1000) // timeout in milliseconds
},
function (err, res) {
if (err){
console.log(err);
}else{
console.log(res.body);
}
}
);

33

httpreq.js

@@ -42,2 +42,6 @@ /*

if(moreOptions.maxRedirects === undefined){
moreOptions.maxRedirects = 10;
}
doRequest(moreOptions, callback);

@@ -58,2 +62,3 @@ }

function doRequest(o, callback){
var hasTimedout = false;
var chunks = [];

@@ -93,2 +98,6 @@ var body;

if(!o.redirectCount){
o.redirectCount = 0;
}
if(o.method == 'POST' && o.parameters){

@@ -124,4 +133,9 @@ requestoptions['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';

if(res.headers.location && o.allowRedirects){
o.url = res.headers.location;
return doRequest(o, callback);
if(o.redirectCount < o.maxRedirects){
o.redirectCount++;
o.url = res.headers.location;
return doRequest(o, callback);
} else {
return callback(new Error("Too many redirects (> " + o.maxRedirects + ")"));
}
}

@@ -149,4 +163,17 @@

if(o.timeout){
request.setTimeout(o.timeout, function (k, d){
hasTimedout = true;
request.abort();
});
}
request.on('error', function (err) {
callback(err);
if(hasTimedout){
var err = new Error("request timed out");
err.code = 'TIMEOUT';
callback(err);
} else {
callback(err);
}
});

@@ -153,0 +180,0 @@

{
"name": "httpreq",
"description": "node-httpreq is a node.js library to do HTTP(S) requests the easy way",
"version": "0.2.7",
"version": "0.2.8",
"author": {

@@ -18,2 +18,8 @@ "name": "Sam Decrock",

"main": "./httpreq",
"contributors": [
{
"name": "Russell Beattie",
"url": "https://github.com/russellbeattie"
}
],
"licenses": [

@@ -20,0 +26,0 @@ {

@@ -36,2 +36,4 @@ node-httpreq

- allowRedirects: (default: __true__ ...only with httpreq.get ), if true, redirects will be followed
- maxRedirects: (default: 10). For example 1 redirect will allow for one normal request and 1 extra redirected request.
- timeout: (default: none). Adds a timeout to the http(s) request. Should be in milliseconds.
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ), the http status code ( __res.statusCode__ ) and the body ( __res.body__ )

@@ -92,2 +94,4 @@

- allowRedirects: (default: false), if true, redirects will be followed
- maxRedirects: (default: 10). For example 1 redirect will allow for one normal request and 1 extra redirected request.
- timeout: (default: none). Adds a timeout to the http(s) request. Should be in milliseconds.
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ), the http status code ( __res.statusCode__ ) and the body ( __res.body__ )

@@ -189,2 +193,4 @@

- allowRedirects: (default: false), if true, redirects will be followed
- maxRedirects: (default: 10). For example 1 redirect will allow for one normal request and 1 extra redirected request.
- timeout: (default: none). Adds a timeout to the http(s) request. Should be in milliseconds.
- callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ), the http status code ( __res.statusCode__ ) and the body ( __res.body__ )

@@ -191,0 +197,0 @@

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