urllib 2.9.0 → 2.11.1
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/History.md +22 -0
- package/README.md +6 -2
- package/lib/urllib.js +24 -16
- package/package.json +20 -17
package/History.md
CHANGED
@@ -1,4 +1,26 @@
|
|
1
1
|
|
2
|
+
2.11.1 / 2016-08-04
|
3
|
+
==================
|
4
|
+
|
5
|
+
* fix: catch http.request sync error (#199)
|
6
|
+
|
7
|
+
2.11.0 / 2016-06-26
|
8
|
+
==================
|
9
|
+
|
10
|
+
* deps: upgrade deps from ~ to ^ (#189)
|
11
|
+
|
12
|
+
2.10.0 / 2016-06-21
|
13
|
+
==================
|
14
|
+
|
15
|
+
* feat: add an options consumeWriteStream (#187)
|
16
|
+
* chore(package): update statuses to version 1.3.0 (#174)
|
17
|
+
|
18
|
+
2.9.1 / 2016-05-09
|
19
|
+
==================
|
20
|
+
|
21
|
+
* fix: check url before request (#172)
|
22
|
+
* chore(package): update any-promise to version 1.2.0 (#171)
|
23
|
+
|
2
24
|
2.9.0 / 2016-04-21
|
3
25
|
==================
|
4
26
|
|
package/README.md
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
[![appveyor build status][appveyor-image]][appveyor-url]
|
6
6
|
[![Test coverage][codecov-image]][codecov-url]
|
7
7
|
[![David deps][david-image]][david-url]
|
8
|
+
[![Known Vulnerabilities][snyk-image]][snyk-url]
|
8
9
|
[![npm download][download-image]][download-url]
|
9
10
|
|
10
11
|
[npm-image]: https://img.shields.io/npm/v/urllib.svg?style=flat-square
|
@@ -13,10 +14,12 @@
|
|
13
14
|
[travis-url]: https://travis-ci.org/node-modules/urllib
|
14
15
|
[appveyor-image]: https://ci.appveyor.com/api/projects/status/wpnl7r1llxyruja9/branch/master?svg=true
|
15
16
|
[appveyor-url]: https://ci.appveyor.com/project/fengmk2/urllib-54ds2
|
16
|
-
[codecov-image]: https://codecov.io/
|
17
|
-
[codecov-url]: https://codecov.io/
|
17
|
+
[codecov-image]: https://codecov.io/gh/node-modules/urllib/branch/master/graph/badge.svg
|
18
|
+
[codecov-url]: https://codecov.io/gh/node-modules/urllib
|
18
19
|
[david-image]: https://img.shields.io/david/node-modules/urllib.svg?style=flat-square
|
19
20
|
[david-url]: https://david-dm.org/node-modules/urllib
|
21
|
+
[snyk-image]: https://snyk.io/test/npm/urllib/badge.svg?style=flat-square
|
22
|
+
[snyk-url]: https://snyk.io/test/npm/urllib
|
20
23
|
[download-image]: https://img.shields.io/npm/dm/urllib.svg?style=flat-square
|
21
24
|
[download-url]: https://npmjs.org/package/urllib
|
22
25
|
|
@@ -121,6 +124,7 @@ httpclient.request('http://nodejs.org', function (err, body) {
|
|
121
124
|
- ***content*** String | [Buffer](http://nodejs.org/api/buffer.html) - Manually set the content of payload. If set, `data` will be ignored.
|
122
125
|
- ***stream*** [stream.Readable](http://nodejs.org/api/stream.html#stream_class_stream_readable) - Stream to be pipe to the remote. If set, `data` and `content` will be ignored.
|
123
126
|
- ***writeStream*** [stream.Writable](http://nodejs.org/api/stream.html#stream_class_stream_writable) - A writable stream to be piped by the response stream. Responding data will be write to this stream and `callback` will be called with `data` set `null` after finished writing.
|
127
|
+
- ***consumeWriteStream*** [true] - consume the writeStream, invoke the callback after writeStream close.
|
124
128
|
- ***contentType*** String - Type of request data. Could be `json`. If it's `json`, will auto set `Content-Type: application/json` header.
|
125
129
|
- ***dataType*** String - Type of response data. Could be `text` or `json`. If it's `text`, the `callback`ed `data` would be a String. If it's `json`, the `data` of callback would be a parsed JSON Object. Default `callback`ed `data` would be a `Buffer`.
|
126
130
|
- **fixJSONCtlChars** Boolean - Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is `false`.
|
package/lib/urllib.js
CHANGED
@@ -1,21 +1,10 @@
|
|
1
|
-
|
2
|
-
* Copyright(c) node-modules and other contributors.
|
3
|
-
* MIT Licensed
|
4
|
-
*
|
5
|
-
* Authors:
|
6
|
-
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
|
7
|
-
*/
|
8
|
-
|
9
|
-
"use strict";
|
10
|
-
|
11
|
-
/**
|
12
|
-
* Module dependencies.
|
13
|
-
*/
|
1
|
+
'use strict';
|
14
2
|
|
15
3
|
var debug = require('debug')('urllib');
|
16
4
|
var http = require('http');
|
17
5
|
var https = require('https');
|
18
6
|
var urlutil = require('url');
|
7
|
+
var util = require('util');
|
19
8
|
var qs = require('querystring');
|
20
9
|
var zlib = require('zlib');
|
21
10
|
var ua = require('default-user-agent');
|
@@ -82,6 +71,7 @@ var PROTO_RE = /^https?:\/\//i;
|
|
82
71
|
* - {WriteStream} [writeStream]: writable stream to save response data.
|
83
72
|
* If you use this, callback's data should be null.
|
84
73
|
* We will just `pipe(ws, {end: true})`.
|
74
|
+
* - {consumeWriteStream} [true]: consume the writeStream, invoke the callback after writeStream close.
|
85
75
|
* - {String} [method]: optional, could be GET | POST | DELETE | PUT, default is GET
|
86
76
|
* - {String} [contentType]: optional, request data type, could be `json`, default is undefined
|
87
77
|
* - {String} [dataType]: optional, response data type, could be `text` or `json`, default is buffer
|
@@ -173,6 +163,11 @@ exports.requestThunk = function (url, args) {
|
|
173
163
|
|
174
164
|
exports.requestWithCallback = function (url, args, callback) {
|
175
165
|
// requestWithCallback(url, callback)
|
166
|
+
if (!url || (typeof url !== 'string' && typeof url !== 'object')) {
|
167
|
+
var msg = util.format('expect request url to be a string or a http request options, but got %j', url);
|
168
|
+
throw new Error(msg);
|
169
|
+
}
|
170
|
+
|
176
171
|
if (arguments.length === 2 && typeof args === 'function') {
|
177
172
|
callback = args;
|
178
173
|
args = null;
|
@@ -485,7 +480,7 @@ exports.requestWithCallback = function (url, args, callback) {
|
|
485
480
|
|
486
481
|
args.requestUrls.push(url);
|
487
482
|
|
488
|
-
|
483
|
+
function onResponse(res) {
|
489
484
|
debug('Request#%d %s `req response` event emit: status %d, headers: %j',
|
490
485
|
reqId, url, res.statusCode, res.headers);
|
491
486
|
|
@@ -531,7 +526,12 @@ exports.requestWithCallback = function (url, args, callback) {
|
|
531
526
|
writeStream.end();
|
532
527
|
return done(result.error, null, res);
|
533
528
|
}
|
534
|
-
|
529
|
+
// you can set consumeWriteStream false that only wait response end
|
530
|
+
if (args.consumeWriteStream === false) {
|
531
|
+
res.on('end', done.bind(null, null, null, res));
|
532
|
+
} else {
|
533
|
+
writeStream.on('close', done.bind(null, null, null, res));
|
534
|
+
}
|
535
535
|
return res.pipe(writeStream);
|
536
536
|
}
|
537
537
|
|
@@ -628,7 +628,15 @@ exports.requestWithCallback = function (url, args, callback) {
|
|
628
628
|
done(err, data, res);
|
629
629
|
});
|
630
630
|
});
|
631
|
-
}
|
631
|
+
}
|
632
|
+
|
633
|
+
var req;
|
634
|
+
// request headers checker will throw error
|
635
|
+
try {
|
636
|
+
req = httplib.request(options, onResponse);
|
637
|
+
} catch (err) {
|
638
|
+
return done(err);
|
639
|
+
}
|
632
640
|
|
633
641
|
var abortRequest = function () {
|
634
642
|
debug('Request#%d %s abort, connected: %s', reqId, url, connected);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "urllib",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.11.1",
|
4
4
|
"description": "Help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more.",
|
5
5
|
"keywords": [
|
6
6
|
"urllib",
|
@@ -22,37 +22,40 @@
|
|
22
22
|
"url": "git://github.com/node-modules/urllib.git"
|
23
23
|
},
|
24
24
|
"scripts": {
|
25
|
-
"test": "mocha -R spec -t 30000 -r should -r should-http test/*.test.js",
|
26
|
-
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- -t 30000 -r should -r should-http test/*.test.js",
|
25
|
+
"test": "mocha -R spec -t 30000 -r should -r should-http -r intelli-espower-loader test/*.test.js",
|
26
|
+
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- -t 30000 -r should -r should-http -r intelli-espower-loader test/*.test.js",
|
27
27
|
"ci": "npm run lint && npm run test-cov",
|
28
28
|
"lint": "jshint .",
|
29
|
-
"autod": "autod -w --prefix '
|
29
|
+
"autod": "autod -w --prefix '^' -t test -e examples"
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"any-promise": "
|
33
|
-
"debug": "
|
34
|
-
"default-user-agent": "
|
35
|
-
"digest-header": "
|
36
|
-
"humanize-ms": "
|
37
|
-
"iconv-lite": "
|
38
|
-
"media-typer": "
|
39
|
-
"statuses": "
|
32
|
+
"any-promise": "^1.2.0",
|
33
|
+
"debug": "^2.2.0",
|
34
|
+
"default-user-agent": "^1.0.0",
|
35
|
+
"digest-header": "^0.0.1",
|
36
|
+
"humanize-ms": "^1.2.0",
|
37
|
+
"iconv-lite": "^0.4.13",
|
38
|
+
"media-typer": "^0.3.0",
|
39
|
+
"statuses": "^1.3.0"
|
40
40
|
},
|
41
41
|
"devDependencies": {
|
42
|
-
"agentkeepalive": "
|
42
|
+
"agentkeepalive": "2",
|
43
43
|
"autod": "*",
|
44
44
|
"bluebird": "*",
|
45
45
|
"co": "*",
|
46
46
|
"coffee": "1",
|
47
|
-
"formstream": "
|
47
|
+
"formstream": "1",
|
48
|
+
"intelli-espower-loader": "^1.0.1",
|
48
49
|
"istanbul": "*",
|
49
50
|
"jshint": "*",
|
50
51
|
"mocha": "*",
|
51
|
-
"pedding": "
|
52
|
+
"pedding": "1",
|
53
|
+
"power-assert": "^1.4.1",
|
52
54
|
"semver": "5",
|
53
|
-
"should": "
|
55
|
+
"should": "8",
|
54
56
|
"should-http": "*",
|
55
|
-
"tar": "
|
57
|
+
"tar": "2",
|
58
|
+
"through2": "2"
|
56
59
|
},
|
57
60
|
"engines": {
|
58
61
|
"node": ">= 0.10.0"
|