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

urllib

Package Overview
Dependencies
Maintainers
1
Versions
222
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urllib - npm Package Compare versions

Comparing version 0.2.4 to 0.2.5

.jshintrc

77

lib/urllib.js

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

var http = require('http');
var https = require('https');
var urlutil = require('url');

@@ -49,3 +50,3 @@ var qs = require('querystring');

*/
exports.request = function(url, args, callback, context) {
exports.request = function (url, args, callback, context) {
if (typeof args === 'function') {

@@ -63,3 +64,3 @@ context = callback;

var port = info.port || 80;
if (info.protocol == 'https:') {
if (info.protocol === 'https:') {
request_method = https.request;

@@ -80,3 +81,3 @@ if (!info.port) {

if (!args.content) {
if(body && !(body instanceof String || body instanceof Buffer)) {
if (body && !(body instanceof String || body instanceof Buffer)) {
body = qs.stringify(body);

@@ -93,9 +94,9 @@ }

var timer = null;
var req = request_method(options, function(res) {
var req = request_method(options, function (res) {
var chunks = [], size = 0;
res.on('data', function(chunk) {
res.on('data', function (chunk) {
size += chunk.length;
chunks.push(chunk);
});
res.on('end', function() {
res.on('end', function () {
if (timer) {

@@ -106,12 +107,16 @@ clearTimeout(timer);

var data = null;
switch(chunks.length) {
case 0: data = new Buffer(0); break;
case 1: data = chunks[0]; break;
default:
data = new Buffer(size);
for (var i = 0, pos = 0, l = chunks.length; i < l; i++) {
chunks[i].copy(data, pos);
pos += chunks[i].length;
}
break;
switch (chunks.length) {
case 0:
data = new Buffer(0);
break;
case 1:
data = chunks[0];
break;
default:
data = new Buffer(size);
for (var i = 0, pos = 0, l = chunks.length; i < l; i++) {
chunks[i].copy(data, pos);
pos += chunks[i].length;
}
break;
}

@@ -122,3 +127,3 @@ callback.call(context, null, data, res);

var timeout = args.timeout;
timer = setTimeout(function() {
timer = setTimeout(function () {
timer = null;

@@ -128,7 +133,3 @@ req.__isTimeout = true;

}, timeout);
// req.setTimeout(timeout, function() {
// req.__isTimeout = true;
// req.abort();
// });
req.on('error', function(err) {
req.on('error', function (err) {
if (timer) {

@@ -162,25 +163,21 @@ clearTimeout(timer);

*/
exports.getCharset = function getCharset(req, data) {
exports.getCharset = function getCharset(res, data) {
var CHARTSET_RE = /charset=([\w\-]+)/ig;
var charset = null;
var content_type = req.headers['content-type'];
if(!content_type) {
// test before 1024 bytes
var end = data.length;
if(end > 512) {
end = 512;
}
content_type = data.slice(0, end).toString();
var matchs = null;
var end = data.length > 512 ? 512 : data.length;
// console.log(data.toString())
var content_type = res.headers['content-type'];
if (content_type) {
// guest from header first
matchs = CHARTSET_RE.exec(content_type);
}
var matchs = CHARTSET_RE.exec(content_type);
if(matchs) {
charset = matchs[1].toLowerCase();
} else if(req.headers['content-type']) {
if (!matchs) {
// guest from html header
content_type = data.slice(0, end).toString();
matchs = CHARTSET_RE.exec(content_type);
if(matchs) {
charset = matchs[1].toLowerCase();
}
}
return charset;
if (matchs) {
return matchs[1].toLowerCase();
}
return null;
};
{
"name": "urllib",
"version": "0.2.4",
"version": "0.2.5",
"description": "Help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more. Like python's _urllib_ module.",
"keywords": ["urllib", "http", "urlopen"],
"keywords": [ "urllib", "http", "urlopen", "curl", "wget" ],
"author": "fengmk2 <fengmk2@gmail.com> (http://github.com/fengmk2)",
"homepage": "http://github.com/TBEDP/urllib",
"main": "./lib/urllib.js",
"main": "index.js",
"repository": {

@@ -20,9 +20,6 @@ "type": "git",

"should": ">=0.4.2",
"mocha": ">=0.14.1",
"jscoverage" : "~0.1.0"
"mocha": ">=0.14.1"
},
"engines": {
"node": ">=v0.6.10"
},
"engines": { "node": ">= 0.6.10" },
"license": "MIT"
}

@@ -20,3 +20,3 @@ # urllib

urllib.request('http://cnodejs.org/', { wd: 'nodejs' }, function(err, data, res) {
urllib.request('http://cnodejs.org/', { wd: 'nodejs' }, function (err, data, res) {
console.log(res.statusCode);

@@ -30,2 +30,3 @@ console.log(res.headers);

* Upload file.
* Auto redirect handle.

@@ -32,0 +33,0 @@ * Bash auth support.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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