Comparing version 0.2.8 to 0.2.9
@@ -1,4 +0,1 @@ | ||
module.exports = process.env.URLLIB_COV | ||
? require('./lib-cov/urllib') | ||
: require('./lib/urllib'); | ||
module.exports = require('./lib/urllib'); |
{ | ||
"name": "urllib", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "Help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more. Like python's _urllib_ module.", | ||
@@ -16,6 +16,6 @@ "keywords": [ "urllib", "http", "urlopen", "curl", "wget" ], | ||
}, | ||
"dependencies": { | ||
}, | ||
"devDependencies": { | ||
"should": ">=0.4.2", | ||
"pedding": "*", | ||
"agentkeepalive": "*", | ||
"mocha": ">=0.14.1" | ||
@@ -22,0 +22,0 @@ }, |
@@ -5,3 +5,3 @@ /** | ||
var urllib = require('../'); | ||
var urllib = process.env.URLLIB_COV ? require('../lib-cov/urllib') : require('../lib/urllib'); | ||
var should = require('should'); | ||
@@ -11,2 +11,4 @@ var http = require('http'); | ||
var urlutil = require('url'); | ||
var KeepAliveAgent = require('agentkeepalive'); | ||
var pedding = require('pedding'); | ||
@@ -132,10 +134,11 @@ function implode_buffer_chunks(chunks) { | ||
describe('#request()', function () { | ||
// it('should request https success', function (done) { | ||
// urllib.request('https://www.alipay.com/', function (err, data, res) { | ||
// should.not.exist(err); | ||
// res.should.status(200); | ||
// done(); | ||
// }); | ||
// }); | ||
describe('request()', function () { | ||
it('should request https success', function (done) { | ||
urllib.request('https://www.alipay.com/', function (err, data, res) { | ||
should.not.exist(err); | ||
should.ok(Buffer.isBuffer(data)); | ||
res.should.status(200); | ||
done(); | ||
}); | ||
}); | ||
@@ -149,2 +152,3 @@ it('should 301', function (done) { | ||
}); | ||
it('should 302', function (done) { | ||
@@ -156,2 +160,3 @@ urllib.request(host + '/302', function (err, data, res) { | ||
}); | ||
it('should 500ms timeout', function (done) { | ||
@@ -168,2 +173,3 @@ urllib.request(host + '/timeout', { timeout: 450 }, function (err, data, res) { | ||
}); | ||
it('should error', function (done) { | ||
@@ -244,2 +250,15 @@ urllib.request(host + '/error', function (err, data, res) { | ||
it('should post big data with params.data and SlowBuffer', function (done) { | ||
var bigdata = new require('buffer').SlowBuffer(1024 * 1024); | ||
urllib.request(host + '/post', { | ||
type: 'post', | ||
data: bigdata | ||
}, function (err, data, res) { | ||
should.not.exist(err); | ||
res.should.status(200); | ||
data.should.length(bigdata.length); | ||
done(); | ||
}); | ||
}); | ||
it('should handle GET /wrongjson with dataType=json', function (done) { | ||
@@ -257,2 +276,31 @@ urllib.request(host + '/wrongjson', { | ||
}); | ||
describe('support agentkeepalive', function () { | ||
before(function () { | ||
this.agent = new KeepAliveAgent(); | ||
}); | ||
it('should use KeepAlive agent request all urls', function (done) { | ||
var urls = [ | ||
'http://www.taobao.com/', | ||
'http://s.taobao.com/search?spm=1.1000386.220544.1.39f990&q=%C2%E3%D1%A5&refpid=420460_1006&source=tbsy&style=grid&tab=all', | ||
'http://s.taobao.com/search?spm=1.1000386.220544.5.39f990&q=%C7%EF%B4%F2%B5%D7%C9%C0&refpid=420464_1006&source=tbsy&pdc=true&style=grid', | ||
'http://s.taobao.com/search?spm=a230r.1.6.3.d2f979&q=%C5%A3%D7%D0%BF%E3%C5%AE&style=grid&tab=all&source=tbsy&refpid=420467_1006&newpre=null&p4p_str=fp_midtop%3D0%26firstpage_pushleft%3D0&cps=yes&from=compass&cat=50103042&navlog=compass-3-c-50103042', | ||
]; | ||
var agent = this.agent; | ||
done = pedding(urls.length, done); | ||
urls.forEach(function (url) { | ||
urllib.request(url, { | ||
agent: agent, | ||
timeout: 15000, | ||
}, function (err, data, res) { | ||
should.not.exist(err); | ||
data.should.be.an.instanceof(Buffer); | ||
res.should.status(200); | ||
res.should.have.header('connection', 'keep-alive'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -268,3 +316,3 @@ | ||
res.should.status(200); | ||
res.headers['content-type'].should.include('json'); | ||
res.should.have.header('content-type', 'application/json; charset=utf-8'); | ||
done(); | ||
@@ -271,0 +319,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
21837
506
0
4
13
2