Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return Promise when callback missing. fixed #33
- Loading branch information
Showing
6 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var co = require('co'); | ||
var urllib = require('../'); | ||
|
||
co(function* () { | ||
var result = yield urllib.request('http://nodejs.org'); | ||
console.log('status: %s, body size: %d, headers: %j', | ||
result.res.statusCode, result.data.length, result.res.headers); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var urllib = require('../'); | ||
|
||
urllib.request('http://nodejs.org').then(function (result) { | ||
console.log('status: %s, body size: %d, headers: %j', result.res.statusCode, result.data.length, result.res.headers); | ||
}).error(function (err) { | ||
console.error(err); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/**! | ||
* urllib - test/urllib_promise.test.js | ||
* | ||
* Copyright(c) fengmk2 and other contributors. | ||
* MIT Licensed | ||
* | ||
* Authors: | ||
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com) | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var should = require('should'); | ||
var urllib = require('../'); | ||
|
||
describe('urllib_promise.test.js', function () { | ||
it('should return promise when callback missing', function (done) { | ||
urllib.request('http://nodejs.org') | ||
.then(function (result) { | ||
should.exist(result.data); | ||
should.exist(result.res); | ||
result.data.should.be.a.Buffer; | ||
result.res.should.status(200); | ||
result.res.should.have.header('connection', 'keep-alive'); | ||
done(); | ||
}).error(done); | ||
}); | ||
|
||
it('should work with args', function (done) { | ||
urllib.request('http://nodejs.org', { | ||
data: { | ||
q: 'foo' | ||
} | ||
}) | ||
.then(function (result) { | ||
should.exist(result.data); | ||
should.exist(result.res); | ||
result.data.should.be.a.Buffer; | ||
result.res.should.status(200); | ||
result.res.should.have.header('connection', 'keep-alive'); | ||
done(); | ||
}).error(done); | ||
}); | ||
}); |