urllib 2.38.0 → 2.39.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/History.md +21 -0
- package/README.md +11 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.test-d.ts +12 -0
- package/lib/urllib.js +23 -11
- package/package.json +4 -1
package/History.md
CHANGED
@@ -1,4 +1,25 @@
|
|
1
1
|
|
2
|
+
2.39.0 / 2022-10-09
|
3
|
+
==================
|
4
|
+
|
5
|
+
**features**
|
6
|
+
* [[`2896cf0`](http://github.com/node-modules/urllib/commit/2896cf01234184bdefc23506ec6c5aaba81d30c2)] - 👌 IMPROVE: support lower case method on d.ts (#410) (fengmk2 <<fengmk2@gmail.com>>)
|
7
|
+
|
8
|
+
**others**
|
9
|
+
* [[`0a200be`](http://github.com/node-modules/urllib/commit/0a200bec22a4fd6895e864366e66c99a8559e5f8)] - chore: change npm tag to latest-2 (fengmk2 <<fengmk2@gmail.com>>)
|
10
|
+
|
11
|
+
2.38.1 / 2022-07-05
|
12
|
+
==================
|
13
|
+
|
14
|
+
**fixes**
|
15
|
+
* [[`f343daa`](http://github.com/node-modules/urllib/commit/f343daa6d1ffb91ebed00e0f858fcb4378921349)] - fix: ignore request error if request is done (#384) (killa <<killa123@126.com>>)
|
16
|
+
|
17
|
+
**others**
|
18
|
+
* [[`518d22c`](http://github.com/node-modules/urllib/commit/518d22c30e3888e6cffec0572f05af0fc30f824f)] - Create codeql-analysis.yml (fengmk2 <<fengmk2@gmail.com>>)
|
19
|
+
* [[`7daf2fa`](http://github.com/node-modules/urllib/commit/7daf2fa599ac294ffc8a3adfe7015b667f13e59a)] - chore: update contributors (fengmk2 <<fengmk2@gmail.com>>)
|
20
|
+
* [[`20451f2`](http://github.com/node-modules/urllib/commit/20451f2898fba90a72c9b953e518e2f67a3bddd7)] - test: add tsd for timing interface (#377) (fengmk2 <<fengmk2@gmail.com>>)
|
21
|
+
* [[`f662c2b`](http://github.com/node-modules/urllib/commit/f662c2b066d3d4363491ee552a0976fe29a528cf)] - chore: update contributors (fengmk2 <<fengmk2@gmail.com>>)
|
22
|
+
|
2
23
|
2.38.0 / 2021-11-24
|
3
24
|
==================
|
4
25
|
|
package/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# urllib
|
1
|
+
# urllib@2
|
2
2
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
4
4
|
[](https://github.com/node-modules/urllib/actions/workflows/nodejs.yml)
|
@@ -21,7 +21,7 @@ and digest authentication, redirections, cookies, timeout and more.
|
|
21
21
|
## Install
|
22
22
|
|
23
23
|
```bash
|
24
|
-
$ npm install urllib --save
|
24
|
+
$ npm install urllib@2 --save
|
25
25
|
```
|
26
26
|
|
27
27
|
## Usage
|
@@ -443,14 +443,16 @@ When open the trace, urllib may have poor perfomance, please consider carefully.
|
|
443
443
|
|
444
444
|
## Contributors
|
445
445
|
|
446
|
-
|[<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/>|
|
447
447
|
| :---: | :---: | :---: | :---: | :---: | :---: |
|
448
|
-
|[<img src="https://
|
449
|
-
|[<img src="https://
|
450
|
-
|[<img src="https://
|
451
|
-
[<img src="https://
|
452
|
-
|
453
|
-
|
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`.
|
454
456
|
|
455
457
|
<!-- GITCONTRIBUTOR_END -->
|
456
458
|
|
package/lib/index.d.ts
CHANGED
@@ -12,7 +12,7 @@ export type HttpMethod = "GET" | "POST" | "DELETE" | "PUT" | "HEAD" | "OPTIONS"
|
|
12
12
|
export as namespace urllib;
|
13
13
|
export interface RequestOptions {
|
14
14
|
/** Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'. */
|
15
|
-
method?: HttpMethod
|
15
|
+
method?: HttpMethod | Lowercase<HttpMethod>;
|
16
16
|
/** Alias method */
|
17
17
|
type?: HttpMethod;
|
18
18
|
/** Data to be sent. Will be stringify automatically. */
|
package/lib/index.test-d.ts
CHANGED
@@ -8,3 +8,15 @@ expectType<Buffer>((await curl<Buffer>('http://a.com', {})).data);
|
|
8
8
|
expectType<string>((await curl<string>('http://a.com', {
|
9
9
|
method: 'HEAD',
|
10
10
|
})).data);
|
11
|
+
expectType<string>((await curl<string>('http://a.com', {
|
12
|
+
method: 'head',
|
13
|
+
})).data);
|
14
|
+
|
15
|
+
// HttpClientResponse
|
16
|
+
const res = await curl<Buffer>('http://a.com');
|
17
|
+
expectType<number | undefined>(res.res.timing?.queuing);
|
18
|
+
expectType<number | undefined>(res.res.timing?.dnslookup);
|
19
|
+
expectType<number | undefined>(res.res.timing?.connected);
|
20
|
+
expectType<number | undefined>(res.res.timing?.requestSent);
|
21
|
+
expectType<number | undefined>(res.res.timing?.waiting);
|
22
|
+
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,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "urllib",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.39.0",
|
4
|
+
"publishConfig": {
|
5
|
+
"tag": "latest-2"
|
6
|
+
},
|
4
7
|
"description": "Help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more.",
|
5
8
|
"keywords": [
|
6
9
|
"urllib",
|