urllib 2.37.3 → 2.38.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 +28 -0
- package/README.md +11 -15
- package/lib/index.d.ts +13 -1
- package/lib/index.test-d.ts +19 -0
- package/lib/urllib.js +23 -11
- package/package.json +7 -5
package/History.md
CHANGED
@@ -1,4 +1,32 @@
|
|
1
1
|
|
2
|
+
2.38.1 / 2022-07-05
|
3
|
+
==================
|
4
|
+
|
5
|
+
**fixes**
|
6
|
+
* [[`f343daa`](http://github.com/node-modules/urllib/commit/f343daa6d1ffb91ebed00e0f858fcb4378921349)] - fix: ignore request error if request is done (#384) (killa <<killa123@126.com>>)
|
7
|
+
|
8
|
+
**others**
|
9
|
+
* [[`518d22c`](http://github.com/node-modules/urllib/commit/518d22c30e3888e6cffec0572f05af0fc30f824f)] - Create codeql-analysis.yml (fengmk2 <<fengmk2@gmail.com>>)
|
10
|
+
* [[`7daf2fa`](http://github.com/node-modules/urllib/commit/7daf2fa599ac294ffc8a3adfe7015b667f13e59a)] - chore: update contributors (fengmk2 <<fengmk2@gmail.com>>)
|
11
|
+
* [[`20451f2`](http://github.com/node-modules/urllib/commit/20451f2898fba90a72c9b953e518e2f67a3bddd7)] - test: add tsd for timing interface (#377) (fengmk2 <<fengmk2@gmail.com>>)
|
12
|
+
* [[`f662c2b`](http://github.com/node-modules/urllib/commit/f662c2b066d3d4363491ee552a0976fe29a528cf)] - chore: update contributors (fengmk2 <<fengmk2@gmail.com>>)
|
13
|
+
|
14
|
+
2.38.0 / 2021-11-24
|
15
|
+
==================
|
16
|
+
|
17
|
+
**others**
|
18
|
+
* [[`6d19f99`](http://github.com/node-modules/urllib/commit/6d19f99f6490df67832d1d2a9c39743c0de1cbd5)] - tsd: add timing interface (#375) (弘树@阿里 <<dickeylth@users.noreply.github.com>>)
|
19
|
+
* [[`9c9c65b`](http://github.com/node-modules/urllib/commit/9c9c65b0e8344c1a30c157628a675440b8a616c1)] - test: check TypeScript type definitions (#373) (fengmk2 <<fengmk2@gmail.com>>)
|
20
|
+
|
21
|
+
2.37.4 / 2021-09-07
|
22
|
+
==================
|
23
|
+
|
24
|
+
**fixes**
|
25
|
+
* [[`1e6622a`](http://github.com/node-modules/urllib/commit/1e6622a571b3e6f72c5f187a224bddedcbc382cf)] - fix: upgrade proxy-agent to fix the security vulnerability. (#368) (hyj1991 <<yeekwanvong@gmail.com>>)
|
26
|
+
|
27
|
+
**others**
|
28
|
+
* [[`ae27498`](http://github.com/node-modules/urllib/commit/ae2749811e40262da8bf2641599b066344fa6b05)] - docs: notes contentType's value (#349) (changzhi <<changzhiwin@gmail.com>>)
|
29
|
+
|
2
30
|
2.37.3 / 2021-07-05
|
3
31
|
==================
|
4
32
|
|
package/README.md
CHANGED
@@ -1,21 +1,15 @@
|
|
1
1
|
# urllib
|
2
2
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
4
|
-
[](https://dev.azure.com/eggjs/egg/_build/latest?definitionId=7)
|
4
|
+
[](https://github.com/node-modules/urllib/actions/workflows/nodejs.yml)
|
6
5
|
[![Test coverage][codecov-image]][codecov-url]
|
7
|
-
[![David deps][david-image]][david-url]
|
8
6
|
[![Known Vulnerabilities][snyk-image]][snyk-url]
|
9
7
|
[![npm download][download-image]][download-url]
|
10
8
|
|
11
9
|
[npm-image]: https://img.shields.io/npm/v/urllib.svg?style=flat-square
|
12
10
|
[npm-url]: https://npmjs.org/package/urllib
|
13
|
-
[travis-image]: https://img.shields.io/travis/node-modules/urllib.svg?style=flat-square
|
14
|
-
[travis-url]: https://travis-ci.org/node-modules/urllib
|
15
11
|
[codecov-image]: https://codecov.io/gh/node-modules/urllib/branch/master/graph/badge.svg
|
16
12
|
[codecov-url]: https://codecov.io/gh/node-modules/urllib
|
17
|
-
[david-image]: https://img.shields.io/david/node-modules/urllib.svg?style=flat-square
|
18
|
-
[david-url]: https://david-dm.org/node-modules/urllib
|
19
13
|
[snyk-image]: https://snyk.io/test/npm/urllib/badge.svg?style=flat-square
|
20
14
|
[snyk-url]: https://snyk.io/test/npm/urllib
|
21
15
|
[download-image]: https://img.shields.io/npm/dm/urllib.svg?style=flat-square
|
@@ -125,7 +119,7 @@ httpclient.request('http://nodejs.org', function (err, body) {
|
|
125
119
|
- ***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.
|
126
120
|
- ***files*** {Array<ReadStream|Buffer|String> | Object | ReadStream | Buffer | String - The files will send with `multipart/form-data` format, base on `formstream`. If `method` not set, will use `POST` method by default.
|
127
121
|
- ***consumeWriteStream*** [true] - consume the writeStream, invoke the callback after writeStream close.
|
128
|
-
- ***contentType*** String - Type of request data. Could be `json
|
122
|
+
- ***contentType*** String - Type of request data. Could be `json` (**Notes**: not use `application/json` here). If it's `json`, will auto set `Content-Type: application/json` header.
|
129
123
|
- ***nestedQuerystring*** Boolean - urllib default use querystring to stringify form data which don't support nested object, will use [qs](https://github.com/ljharb/qs) instead of querystring to support nested object by set this option to true.
|
130
124
|
- ***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 and will auto set `Accept: application/json` header. Default `callback`ed `data` would be a `Buffer`.
|
131
125
|
- **fixJSONCtlChars** Boolean - Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is `false`.
|
@@ -449,14 +443,16 @@ When open the trace, urllib may have poor perfomance, please consider carefully.
|
|
449
443
|
|
450
444
|
## Contributors
|
451
445
|
|
452
|
-
|[<img src="https://
|
446
|
+
|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/985607?v=4" width="100px;"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|[<img src="https://avatars.githubusercontent.com/u/288288?v=4" width="100px;"/><br/><sub><b>xingrz</b></sub>](https://github.com/xingrz)<br/>|[<img src="https://avatars.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/>|[<img src="https://avatars.githubusercontent.com/u/327019?v=4" width="100px;"/><br/><sub><b>JacksonTian</b></sub>](https://github.com/JacksonTian)<br/>|[<img src="https://avatars.githubusercontent.com/u/543405?v=4" width="100px;"/><br/><sub><b>ibigbug</b></sub>](https://github.com/ibigbug)<br/>|
|
453
447
|
| :---: | :---: | :---: | :---: | :---: | :---: |
|
454
|
-
|[<img src="https://
|
455
|
-
|[<img src="https://
|
456
|
-
|[<img src="https://
|
457
|
-
[<img src="https://
|
458
|
-
|
459
|
-
|
448
|
+
|[<img src="https://avatars.githubusercontent.com/u/14790466?v=4" width="100px;"/><br/><sub><b>greenkeeperio-bot</b></sub>](https://github.com/greenkeeperio-bot)<br/>|[<img src="https://avatars.githubusercontent.com/u/227713?v=4" width="100px;"/><br/><sub><b>atian25</b></sub>](https://github.com/atian25)<br/>|[<img src="https://avatars.githubusercontent.com/u/5381764?v=4" width="100px;"/><br/><sub><b>paambaati</b></sub>](https://github.com/paambaati)<br/>|[<img src="https://avatars.githubusercontent.com/u/1433247?v=4" width="100px;"/><br/><sub><b>denghongcai</b></sub>](https://github.com/denghongcai)<br/>|[<img src="https://avatars.githubusercontent.com/u/2842176?v=4" width="100px;"/><br/><sub><b>XadillaX</b></sub>](https://github.com/XadillaX)<br/>|[<img src="https://avatars.githubusercontent.com/u/1147375?v=4" width="100px;"/><br/><sub><b>alsotang</b></sub>](https://github.com/alsotang)<br/>|
|
449
|
+
|[<img src="https://avatars.githubusercontent.com/u/546535?v=4" width="100px;"/><br/><sub><b>leoner</b></sub>](https://github.com/leoner)<br/>|[<img src="https://avatars.githubusercontent.com/u/19908330?v=4" width="100px;"/><br/><sub><b>hyj1991</b></sub>](https://github.com/hyj1991)<br/>|[<img src="https://avatars.githubusercontent.com/u/1747852?v=4" width="100px;"/><br/><sub><b>isayme</b></sub>](https://github.com/isayme)<br/>|[<img src="https://avatars.githubusercontent.com/u/6897780?v=4" width="100px;"/><br/><sub><b>killagu</b></sub>](https://github.com/killagu)<br/>|[<img src="https://avatars.githubusercontent.com/u/252317?v=4" width="100px;"/><br/><sub><b>cyjake</b></sub>](https://github.com/cyjake)<br/>|[<img src="https://avatars.githubusercontent.com/u/5856440?v=4" width="100px;"/><br/><sub><b>whxaxes</b></sub>](https://github.com/whxaxes)<br/>|
|
450
|
+
|[<img src="https://avatars.githubusercontent.com/u/309219?v=4" width="100px;"/><br/><sub><b>chadxz</b></sub>](https://github.com/chadxz)<br/>|[<img src="https://avatars.githubusercontent.com/u/5139554?v=4" width="100px;"/><br/><sub><b>danielwpz</b></sub>](https://github.com/danielwpz)<br/>|[<img src="https://avatars.githubusercontent.com/u/5127897?v=4" width="100px;"/><br/><sub><b>danielsss</b></sub>](https://github.com/danielsss)<br/>|[<img src="https://avatars.githubusercontent.com/u/3367820?v=4" width="100px;"/><br/><sub><b>Jeff-Tian</b></sub>](https://github.com/Jeff-Tian)<br/>|[<img src="https://avatars.githubusercontent.com/u/32407?v=4" width="100px;"/><br/><sub><b>jedahan</b></sub>](https://github.com/jedahan)<br/>|[<img src="https://avatars.githubusercontent.com/u/17075261?v=4" width="100px;"/><br/><sub><b>nick-ng</b></sub>](https://github.com/nick-ng)<br/>|
|
451
|
+
|[<img src="https://avatars.githubusercontent.com/u/1706595?v=4" width="100px;"/><br/><sub><b>rishavsharan</b></sub>](https://github.com/rishavsharan)<br/>|[<img src="https://avatars.githubusercontent.com/u/1886161?v=4" width="100px;"/><br/><sub><b>willizm</b></sub>](https://github.com/willizm)<br/>|[<img src="https://avatars.githubusercontent.com/u/7227589?v=4" width="100px;"/><br/><sub><b>davidkhala</b></sub>](https://github.com/davidkhala)<br/>|[<img src="https://avatars.githubusercontent.com/u/535479?v=4" width="100px;"/><br/><sub><b>aleafs</b></sub>](https://github.com/aleafs)<br/>|[<img src="https://avatars.githubusercontent.com/u/3689968?v=4" width="100px;"/><br/><sub><b>Amunu</b></sub>](https://github.com/Amunu)<br/>|[<img src="https://avatars.githubusercontent.com/in/9426?v=4" width="100px;"/><br/><sub><b>azure-pipelines[bot]</b></sub>](https://github.com/apps/azure-pipelines)<br/>|
|
452
|
+
|[<img src="https://avatars.githubusercontent.com/u/1281323?v=4" width="100px;"/><br/><sub><b>changzhiwin</b></sub>](https://github.com/changzhiwin)<br/>|[<img src="https://avatars.githubusercontent.com/u/929503?v=4" width="100px;"/><br/><sub><b>yuzhigang33</b></sub>](https://github.com/yuzhigang33)<br/>|[<img src="https://avatars.githubusercontent.com/u/981128?v=4" width="100px;"/><br/><sub><b>fishbar</b></sub>](https://github.com/fishbar)<br/>|[<img src="https://avatars.githubusercontent.com/u/1207064?v=4" width="100px;"/><br/><sub><b>gxcsoccer</b></sub>](https://github.com/gxcsoccer)<br/>|[<img src="https://avatars.githubusercontent.com/u/17476119?v=4" width="100px;"/><br/><sub><b>mars-coder</b></sub>](https://github.com/mars-coder)<br/>|[<img src="https://avatars.githubusercontent.com/u/929179?v=4" width="100px;"/><br/><sub><b>rockdai</b></sub>](https://github.com/rockdai)<br/>|
|
453
|
+
[<img src="https://avatars.githubusercontent.com/u/2196373?v=4" width="100px;"/><br/><sub><b>dickeylth</b></sub>](https://github.com/dickeylth)<br/>|[<img src="https://avatars.githubusercontent.com/u/13050025?v=4" width="100px;"/><br/><sub><b>aladdin-add</b></sub>](https://github.com/aladdin-add)<br/>
|
454
|
+
|
455
|
+
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Tue Jul 05 2022 16:17:31 GMT+0800`.
|
460
456
|
|
461
457
|
<!-- GITCONTRIBUTOR_END -->
|
462
458
|
|
package/lib/index.d.ts
CHANGED
@@ -140,7 +140,19 @@ export interface HttpClientResponse<T> {
|
|
140
140
|
data: T;
|
141
141
|
status: number;
|
142
142
|
headers: OutgoingHttpHeaders;
|
143
|
-
res: http.IncomingMessage
|
143
|
+
res: http.IncomingMessage & {
|
144
|
+
/**
|
145
|
+
* https://eggjs.org/en/core/httpclient.html#timing-boolean
|
146
|
+
*/
|
147
|
+
timing?: {
|
148
|
+
queuing: number;
|
149
|
+
dnslookup: number;
|
150
|
+
connected: number;
|
151
|
+
requestSent: number;
|
152
|
+
waiting: number;
|
153
|
+
contentDownload: number;
|
154
|
+
}
|
155
|
+
};
|
144
156
|
}
|
145
157
|
|
146
158
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { expectType } from 'tsd';
|
2
|
+
import { curl } from '..';
|
3
|
+
|
4
|
+
// curl
|
5
|
+
expectType<Buffer>((await curl<Buffer>('http://a.com')).data);
|
6
|
+
// RequestOptions
|
7
|
+
expectType<Buffer>((await curl<Buffer>('http://a.com', {})).data);
|
8
|
+
expectType<string>((await curl<string>('http://a.com', {
|
9
|
+
method: 'HEAD',
|
10
|
+
})).data);
|
11
|
+
|
12
|
+
// HttpClientResponse
|
13
|
+
const res = await curl<Buffer>('http://a.com');
|
14
|
+
expectType<number | undefined>(res.res.timing?.queuing);
|
15
|
+
expectType<number | undefined>(res.res.timing?.dnslookup);
|
16
|
+
expectType<number | undefined>(res.res.timing?.connected);
|
17
|
+
expectType<number | undefined>(res.res.timing?.requestSent);
|
18
|
+
expectType<number | undefined>(res.res.timing?.waiting);
|
19
|
+
expectType<number | undefined>(res.res.timing?.contentDownload);
|
package/lib/urllib.js
CHANGED
@@ -728,6 +728,13 @@ function requestWithCallback(url, args, callback) {
|
|
728
728
|
}
|
729
729
|
|
730
730
|
function decodeContent(res, body, cb) {
|
731
|
+
if (responseAborted) {
|
732
|
+
// err = new Error('Remote socket was terminated before `response.end()` was called');
|
733
|
+
// err.name = 'RemoteSocketClosedError';
|
734
|
+
debug('Request#%d %s: Remote socket was terminated before `response.end()` was called', reqId, url);
|
735
|
+
var err = responseError || new Error('Remote socket was terminated before `response.end()` was called');
|
736
|
+
return cb(err);
|
737
|
+
}
|
731
738
|
var encoding = res.headers['content-encoding'];
|
732
739
|
if (body.length === 0 || !encoding) {
|
733
740
|
return cb(null, body, encoding);
|
@@ -758,7 +765,10 @@ function requestWithCallback(url, args, callback) {
|
|
758
765
|
|
759
766
|
args.requestUrls.push(parsedUrl.href);
|
760
767
|
|
768
|
+
var hasResponse = false;
|
769
|
+
var responseError;
|
761
770
|
function onResponse(res) {
|
771
|
+
hasResponse = true;
|
762
772
|
socketHandledResponses = res.socket[SOCKET_RESPONSE_COUNT] = (res.socket[SOCKET_RESPONSE_COUNT] || 0) + 1;
|
763
773
|
if (timing) {
|
764
774
|
timing.waiting = Date.now() - requestStartTime;
|
@@ -781,7 +791,8 @@ function requestWithCallback(url, args, callback) {
|
|
781
791
|
return done(null, null, res);
|
782
792
|
}
|
783
793
|
|
784
|
-
res.on('error', function () {
|
794
|
+
res.on('error', function (err) {
|
795
|
+
responseError = err;
|
785
796
|
debug('Request#%d %s: `res error` event emit, total size %d, socket handled %s requests and %s responses',
|
786
797
|
reqId, url, responseSize, socketHandledRequests, socketHandledResponses);
|
787
798
|
});
|
@@ -939,12 +950,6 @@ function requestWithCallback(url, args, callback) {
|
|
939
950
|
}
|
940
951
|
}
|
941
952
|
|
942
|
-
if (responseAborted) {
|
943
|
-
// err = new Error('Remote socket was terminated before `response.end()` was called');
|
944
|
-
// err.name = 'RemoteSocketClosedError';
|
945
|
-
debug('Request#%d %s: Remote socket was terminated before `response.end()` was called', reqId, url);
|
946
|
-
}
|
947
|
-
|
948
953
|
done(err, data, res);
|
949
954
|
});
|
950
955
|
}
|
@@ -1161,12 +1166,17 @@ function requestWithCallback(url, args, callback) {
|
|
1161
1166
|
});
|
1162
1167
|
}
|
1163
1168
|
|
1164
|
-
var
|
1169
|
+
var isRequestDone = false;
|
1165
1170
|
function handleRequestError(err) {
|
1166
|
-
if (
|
1171
|
+
if (!err) {
|
1167
1172
|
return;
|
1168
1173
|
}
|
1169
|
-
|
1174
|
+
// only ignore request error if response has been received
|
1175
|
+
// if response has not received, socket error will emit on req
|
1176
|
+
if (isRequestDone && hasResponse) {
|
1177
|
+
return;
|
1178
|
+
}
|
1179
|
+
isRequestDone = true;
|
1170
1180
|
|
1171
1181
|
if (err.name === 'Error') {
|
1172
1182
|
err.name = connected ? 'ResponseError' : 'RequestError';
|
@@ -1178,7 +1188,9 @@ function requestWithCallback(url, args, callback) {
|
|
1178
1188
|
debug('Request#%d pump args.stream to req', reqId);
|
1179
1189
|
pump(args.stream, req, handleRequestError);
|
1180
1190
|
} else {
|
1181
|
-
req.end(body)
|
1191
|
+
req.end(body, function () {
|
1192
|
+
isRequestDone = true;
|
1193
|
+
});
|
1182
1194
|
}
|
1183
1195
|
// when stream already consumed, req's `finish` event is emitted and pump will ignore error after pipe finished
|
1184
1196
|
// but if server response timeout later, we will abort the request and emit an error in req
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "urllib",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.38.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",
|
@@ -23,10 +23,11 @@
|
|
23
23
|
"url": "git://github.com/node-modules/urllib.git"
|
24
24
|
},
|
25
25
|
"scripts": {
|
26
|
+
"tsd": "node test/tsd.js",
|
26
27
|
"test-local": "mocha -t 30000 -r intelli-espower-loader test/*.test.js",
|
27
28
|
"test": "npm run lint && npm run test-local",
|
28
29
|
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- -t 30000 -r intelli-espower-loader test/*.test.js",
|
29
|
-
"ci": "npm run lint && npm run test-cov",
|
30
|
+
"ci": "npm run lint && npm run tsd && npm run test-cov",
|
30
31
|
"lint": "jshint .",
|
31
32
|
"autod": "autod -w --prefix '^' -t test -e examples",
|
32
33
|
"contributor": "git-contributor"
|
@@ -42,7 +43,7 @@
|
|
42
43
|
"humanize-ms": "^1.2.0",
|
43
44
|
"iconv-lite": "^0.4.15",
|
44
45
|
"ip": "^1.1.5",
|
45
|
-
"proxy-agent": "^
|
46
|
+
"proxy-agent": "^5.0.0",
|
46
47
|
"pump": "^3.0.0",
|
47
48
|
"qs": "^6.4.0",
|
48
49
|
"statuses": "^1.3.1",
|
@@ -73,7 +74,8 @@
|
|
73
74
|
"spy": "^1.0.0",
|
74
75
|
"tar": "^4.4.8",
|
75
76
|
"through2": "^2.0.3",
|
76
|
-
"
|
77
|
+
"tsd": "^0.18.0",
|
78
|
+
"typescript": "^4.4.4"
|
77
79
|
},
|
78
80
|
"engines": {
|
79
81
|
"node": ">= 0.10.0"
|
@@ -83,7 +85,7 @@
|
|
83
85
|
"os": {
|
84
86
|
"github": "linux, windows, macos"
|
85
87
|
},
|
86
|
-
"version": "8, 10, 12, 14"
|
88
|
+
"version": "8, 10, 12, 14, 16"
|
87
89
|
},
|
88
90
|
"license": "MIT"
|
89
91
|
}
|