got 0.2.0 → 0.3.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 +17 -2
- package/package.json +1 -1
- package/readme.md +7 -3
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
var urlLib = require('url');
|
|
3
3
|
var http = require('http');
|
|
4
4
|
var https = require('https');
|
|
5
|
+
var zlib = require('zlib');
|
|
5
6
|
var assign = require('object-assign');
|
|
6
7
|
|
|
7
8
|
module.exports = function (url, opts, cb) {
|
|
@@ -14,6 +15,12 @@ module.exports = function (url, opts, cb) {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
cb = cb || function () {};
|
|
18
|
+
opts = opts || {};
|
|
19
|
+
|
|
20
|
+
opts.headers = assign({
|
|
21
|
+
'user-agent': 'https://github.com/sindresorhus/got',
|
|
22
|
+
'accept-encoding': 'gzip,deflate'
|
|
23
|
+
}, opts.headers || {});
|
|
17
24
|
|
|
18
25
|
var parsedUrl = urlLib.parse(url);
|
|
19
26
|
var fn = parsedUrl.protocol === 'https:' ? https : http;
|
|
@@ -41,16 +48,24 @@ module.exports = function (url, opts, cb) {
|
|
|
41
48
|
return;
|
|
42
49
|
}
|
|
43
50
|
|
|
51
|
+
if (['gzip', 'deflate'].indexOf(res.headers['content-encoding']) !== -1) {
|
|
52
|
+
var unzip = zlib.createUnzip();
|
|
53
|
+
res.pipe(unzip);
|
|
54
|
+
res = unzip;
|
|
55
|
+
}
|
|
56
|
+
|
|
44
57
|
res.setEncoding('utf8');
|
|
45
58
|
|
|
46
59
|
res.on('data', function (data) {
|
|
47
60
|
ret += data;
|
|
48
61
|
});
|
|
49
62
|
|
|
50
|
-
res.
|
|
63
|
+
res.once('error', cb);
|
|
64
|
+
|
|
65
|
+
res.once('end', function () {
|
|
51
66
|
cb(null, ret);
|
|
52
67
|
});
|
|
53
|
-
}).
|
|
68
|
+
}).once('error', cb);
|
|
54
69
|
};
|
|
55
70
|
|
|
56
71
|
get(url, opts, cb);
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
> Simplified HTTP/HTTPS requests
|
|
4
4
|
|
|
5
|
-
A nicer interface to the built-in [`http`](http://nodejs.org/api/http.html) module
|
|
5
|
+
A nicer interface to the built-in [`http`](http://nodejs.org/api/http.html) module.
|
|
6
|
+
|
|
7
|
+
It also supports following redirects and automagically handling gzip/deflate.
|
|
8
|
+
|
|
9
|
+
Use [request](https://github.com/mikeal/request) if you need more.
|
|
6
10
|
|
|
7
11
|
|
|
8
12
|
## Install
|
|
9
13
|
|
|
10
|
-
```
|
|
14
|
+
```sh
|
|
11
15
|
$ npm install --save got
|
|
12
16
|
```
|
|
13
17
|
|
|
@@ -48,4 +52,4 @@ Any of the [`http.request`](http://nodejs.org/api/http.html#http_http_request_op
|
|
|
48
52
|
|
|
49
53
|
## License
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
MIT © [Sindre Sorhus](http://sindresorhus.com)
|