got 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +15 -5
- package/package.json +5 -2
- package/readme.md +24 -2
package/index.js
CHANGED
|
@@ -2,14 +2,24 @@
|
|
|
2
2
|
var urlLib = require('url');
|
|
3
3
|
var http = require('http');
|
|
4
4
|
var https = require('https');
|
|
5
|
+
var assign = require('object-assign');
|
|
5
6
|
|
|
6
|
-
module.exports = function (url, cb) {
|
|
7
|
+
module.exports = function (url, opts, cb) {
|
|
7
8
|
var redirectCount = 0;
|
|
8
9
|
|
|
9
|
-
var get = function (url, cb) {
|
|
10
|
-
|
|
10
|
+
var get = function (url, opts, cb) {
|
|
11
|
+
if (typeof opts === 'function') {
|
|
12
|
+
cb = opts;
|
|
13
|
+
opts = {};
|
|
14
|
+
}
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
cb = cb || function () {};
|
|
17
|
+
|
|
18
|
+
var parsedUrl = urlLib.parse(url);
|
|
19
|
+
var fn = parsedUrl.protocol === 'https:' ? https : http;
|
|
20
|
+
var arg = assign({}, parsedUrl, opts);
|
|
21
|
+
|
|
22
|
+
fn.get(arg, function (res) {
|
|
13
23
|
var ret = '';
|
|
14
24
|
|
|
15
25
|
// redirect
|
|
@@ -43,5 +53,5 @@ module.exports = function (url, cb) {
|
|
|
43
53
|
}).on('error', cb);
|
|
44
54
|
};
|
|
45
55
|
|
|
46
|
-
get(url, cb);
|
|
56
|
+
get(url, opts, cb);
|
|
47
57
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "got",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Simplified HTTP/HTTPS
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Simplified HTTP/HTTPS requests",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/got",
|
|
7
7
|
"author": {
|
|
@@ -30,6 +30,9 @@
|
|
|
30
30
|
"utility",
|
|
31
31
|
"simple"
|
|
32
32
|
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"object-assign": "^0.3.0"
|
|
35
|
+
},
|
|
33
36
|
"devDependencies": {
|
|
34
37
|
"mocha": "*"
|
|
35
38
|
}
|
package/readme.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# got [](https://travis-ci.org/sindresorhus/got)
|
|
2
2
|
|
|
3
|
-
> Simplified HTTP/HTTPS
|
|
3
|
+
> Simplified HTTP/HTTPS requests
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A nicer interface to the built-in [`http`](http://nodejs.org/api/http.html) module that also follows redirects. Use [request](https://github.com/mikeal/request) if you need more.
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
## Install
|
|
@@ -24,6 +24,28 @@ got('http://todomvc.com', function (err, data) {
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
|
|
27
|
+
### API
|
|
28
|
+
|
|
29
|
+
It's a `GET` request by default, but can be changed in `options`.
|
|
30
|
+
|
|
31
|
+
#### got(url, [options], [callback])
|
|
32
|
+
|
|
33
|
+
##### url
|
|
34
|
+
|
|
35
|
+
*Required*
|
|
36
|
+
Type: `string`
|
|
37
|
+
|
|
38
|
+
The url to request.
|
|
39
|
+
|
|
40
|
+
##### options
|
|
41
|
+
|
|
42
|
+
Type: `object`
|
|
43
|
+
|
|
44
|
+
Any of the [`http.request`](http://nodejs.org/api/http.html#http_http_request_options_callback) options.
|
|
45
|
+
|
|
46
|
+
##### callback(err, data)
|
|
47
|
+
|
|
48
|
+
|
|
27
49
|
## License
|
|
28
50
|
|
|
29
51
|
[MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com)
|