Skip to content

Commit

Permalink
fix: add alias urllib.curl()
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Aug 12, 2015
1 parent 539acb5 commit 88fe1b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
sudo: false
language: node_js
node_js:
- 'iojs-2'
- 'iojs-1'
- '3'
- '2'
- '1'
- '0.12'
- '0.11.12'
- '0.10'
Expand Down
3 changes: 3 additions & 0 deletions lib/urllib.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ exports.request = function (url, args, callback) {
});
};

// alias to curl
exports.curl = exports.request;

function makeCallback(resolve, reject) {
return function (err, data, res) {
if (err) {
Expand Down
35 changes: 22 additions & 13 deletions test/urllib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ describe('urllib.test.js', function () {
});
});

it('should alias curl() work', function (done) {
urllib.curl('http://cnpmjs.org/mirrors/iojs/v1.2.0/SHASUMS256.txt', {timeout: 10000},
function (err, data, res) {
should.not.exist(err);
should.ok(Buffer.isBuffer(data));
res.should.status(200);
done();
});
});

it('should 301', function (done) {
urllib.request(host + '/301', function (err, data, res) {
res.should.status(301);
Expand Down Expand Up @@ -530,14 +540,13 @@ describe('urllib.test.js', function () {
});

var urls = [
'http://r.cnpmjs.org/byte',
'https://cnpmjs.org/',
'http://r.cnpmjs.org/byte',
'https://cnpmjs.org/',
'https://cnpmjs.org/package/pedding',
'https://cnpmjs.org/package/byte',
'http://r.cnpmjs.org/pedding',
'https://cnpmjs.org/package/ms',
'http://registry.npm.taobao.org/byte',
'https://www.npmjs.com',
'http://npm.taobao.org/',
'http://npm.taobao.org/package/byte',
'https://www.npmjs.com/package/byte',
'http://registry.npm.taobao.org/pedding',
'http://npm.taobao.org/package/ms',
];

urls.forEach(function (url, index) {
Expand All @@ -555,7 +564,7 @@ describe('urllib.test.js', function () {
console.log(res.statusCode, res.headers);
}
res.should.have.header('connection', 'keep-alive');
if (index >= 2) {
if (index >= 3) {
res.keepAliveSocket.should.equal(true);
}
done();
Expand All @@ -566,7 +575,7 @@ describe('urllib.test.js', function () {
it('should request http timeout', function (done) {
var agent = this.agent;
var httpsAgent = this.httpsAgent;
urllib.request('http://r.cnpmjs.org/byte', {
urllib.request('http://registry.npm.taobao.org/byte', {
agent: agent,
httpsAgent: httpsAgent,
timeout: 15000,
Expand All @@ -576,7 +585,7 @@ describe('urllib.test.js', function () {
res.statusCode.should.equal(200);
// make sure free socket release to free list
process.nextTick(function () {
urllib.request('http://r.cnpmjs.org/npm', {
urllib.request('http://registry.npm.taobao.org/npm', {
agent: agent,
httpsAgent: httpsAgent,
timeout: 100,
Expand All @@ -592,7 +601,7 @@ describe('urllib.test.js', function () {
it('should request https timeout', function (done) {
var agent = this.agent;
var httpsAgent = this.httpsAgent;
urllib.request('https://r.cnpmjs.org/koa', {
urllib.request('https://registry.npmjs.com/koa', {
agent: agent,
httpsAgent: httpsAgent,
timeout: 15000,
Expand All @@ -602,7 +611,7 @@ describe('urllib.test.js', function () {
res.statusCode.should.equal(200);
// make sure free socket release to free list
process.nextTick(function () {
urllib.request('https://r.cnpmjs.org/npm', {
urllib.request('https://registry.npmjs.com/npm', {
agent: agent,
httpsAgent: httpsAgent,
timeout: 100,
Expand Down

0 comments on commit 88fe1b2

Please sign in to comment.