urllib 2.37.0 → 2.37.4

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 CHANGED
@@ -1,4 +1,31 @@
1
1
 
2
+ 2.37.4 / 2021-09-07
3
+ ==================
4
+
5
+ **fixes**
6
+ * [[`1e6622a`](http://github.com/node-modules/urllib/commit/1e6622a571b3e6f72c5f187a224bddedcbc382cf)] - fix: upgrade proxy-agent to fix the security vulnerability. (#368) (hyj1991 <<yeekwanvong@gmail.com>>)
7
+
8
+ **others**
9
+ * [[`ae27498`](http://github.com/node-modules/urllib/commit/ae2749811e40262da8bf2641599b066344fa6b05)] - docs: notes contentType's value (#349) (changzhi <<changzhiwin@gmail.com>>)
10
+
11
+ 2.37.3 / 2021-07-05
12
+ ==================
13
+
14
+ **fixes**
15
+ * [[`b730a6c`](http://github.com/node-modules/urllib/commit/b730a6cdc0465bea1c08d50bfa3b5e95bd17b31f)] - fix: 🐛 redirect status code (#363) (Hongcai Deng <<admin@dhchouse.com>>)
16
+
17
+ 2.37.2 / 2021-06-07
18
+ ==================
19
+
20
+ **fixes**
21
+ * [[`04734a1`](http://github.com/node-modules/urllib/commit/04734a13e146da501f4e38333d5de9f9bbb259d1)] - fix: 🐛 should trigger response event when follow redirect (#361) (Hongcai Deng <<admin@dhchouse.com>>)
22
+
23
+ 2.37.1 / 2021-04-15
24
+ ==================
25
+
26
+ **others**
27
+ * [[`d50afda`](http://github.com/node-modules/urllib/commit/d50afda91befff75f044a1ad83689f7a459c5d32)] - Update proxy-agent to v4 to resolve vulnerability (#355) (Chad McElligott <<chad.mcelligott@gmail.com>>)
28
+
2
29
  2.37.0 / 2021-04-02
3
30
  ==================
4
31
 
package/README.md CHANGED
@@ -125,7 +125,7 @@ httpclient.request('http://nodejs.org', function (err, body) {
125
125
  - ***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
126
  - ***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
127
  - ***consumeWriteStream*** [true] - consume the writeStream, invoke the callback after writeStream close.
128
- - ***contentType*** String - Type of request data. Could be `json`. If it's `json`, will auto set `Content-Type: application/json` header.
128
+ - ***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
129
  - ***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
130
  - ***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
131
  - **fixJSONCtlChars** Boolean - Fix the control characters (U+0000 through U+001F) before JSON parse response. Default is `false`.
package/lib/urllib.js CHANGED
@@ -520,6 +520,7 @@ function requestWithCallback(url, args, callback) {
520
520
  }
521
521
  return;
522
522
  }
523
+
523
524
  var cb = callback;
524
525
  callback = null;
525
526
  var headers = {};
@@ -529,49 +530,16 @@ function requestWithCallback(url, args, callback) {
529
530
  headers = res.headers;
530
531
  }
531
532
 
532
- // handle digest auth
533
- if (statusCode === 401 && headers['www-authenticate']
534
- && !options.headers.authorization && args.digestAuth) {
535
- var authenticate = headers['www-authenticate'];
536
- if (authenticate.indexOf('Digest ') >= 0) {
537
- debug('Request#%d %s: got digest auth header WWW-Authenticate: %s', reqId, url, authenticate);
538
- options.headers.authorization = digestAuthHeader(options.method, options.path, authenticate, args.digestAuth);
539
- debug('Request#%d %s: auth with digest header: %s', reqId, url, options.headers.authorization);
540
- if (res.headers['set-cookie']) {
541
- options.headers.cookie = res.headers['set-cookie'].join(';');
542
- }
543
- args.headers = options.headers;
544
- return exports.requestWithCallback(url, args, cb);
545
- }
533
+ if (handleDigestAuth(res, cb)) {
534
+ return;
546
535
  }
547
536
 
548
- var requestUseTime = Date.now() - requestStartTime;
549
- if (timing) {
550
- timing.contentDownload = requestUseTime;
551
- }
537
+ var response = createCallbackResponse(data, res);
552
538
 
553
539
  debug('[%sms] done, %s bytes HTTP %s %s %s %s, keepAliveSocket: %s, timing: %j, socketHandledRequests: %s, socketHandledResponses: %s',
554
- requestUseTime, responseSize, statusCode, options.method, options.host, options.path,
540
+ response.requestUseTime, responseSize, statusCode, options.method, options.host, options.path,
555
541
  keepAliveSocket, timing, socketHandledRequests, socketHandledResponses);
556
542
 
557
- var response = {
558
- status: statusCode,
559
- statusCode: statusCode,
560
- statusMessage: statusMessage,
561
- headers: headers,
562
- size: responseSize,
563
- aborted: responseAborted,
564
- rt: requestUseTime,
565
- keepAliveSocket: keepAliveSocket,
566
- data: data,
567
- requestUrls: args.requestUrls,
568
- timing: timing,
569
- remoteAddress: remoteAddress,
570
- remotePort: remotePort,
571
- socketHandledRequests: socketHandledRequests,
572
- socketHandledResponses: socketHandledResponses,
573
- };
574
-
575
543
  if (err) {
576
544
  var agentStatus = '';
577
545
  if (agent && typeof agent.getCurrentStatus === 'function') {
@@ -620,6 +588,44 @@ function requestWithCallback(url, args, callback) {
620
588
 
621
589
  cb(err, data, args.streaming ? res : response);
622
590
 
591
+ emitResponseEvent(err, response);
592
+ }
593
+
594
+ function createAndEmitResponseEvent(data, res) {
595
+ var response = createCallbackResponse(data, res);
596
+ emitResponseEvent(null, response);
597
+ }
598
+
599
+ function createCallbackResponse(data, res) {
600
+ var requestUseTime = Date.now() - requestStartTime;
601
+ if (timing) {
602
+ timing.contentDownload = requestUseTime;
603
+ }
604
+
605
+ var headers = res && res.headers || {};
606
+ var resStatusCode = res && res.statusCode || statusCode;
607
+ var resStatusMessage = res && res.statusMessage || statusMessage;
608
+
609
+ return {
610
+ status: resStatusCode,
611
+ statusCode: resStatusCode,
612
+ statusMessage: resStatusMessage,
613
+ headers: headers,
614
+ size: responseSize,
615
+ aborted: responseAborted,
616
+ rt: requestUseTime,
617
+ keepAliveSocket: keepAliveSocket,
618
+ data: data,
619
+ requestUrls: args.requestUrls,
620
+ timing: timing,
621
+ remoteAddress: remoteAddress,
622
+ remotePort: remotePort,
623
+ socketHandledRequests: socketHandledRequests,
624
+ socketHandledResponses: socketHandledResponses,
625
+ };
626
+ }
627
+
628
+ function emitResponseEvent(err, response) {
623
629
  if (args.emitter) {
624
630
  // keep to use the same reqMeta object on request event before
625
631
  reqMeta.url = parsedUrl.href;
@@ -637,6 +643,30 @@ function requestWithCallback(url, args, callback) {
637
643
  }
638
644
  }
639
645
 
646
+ function handleDigestAuth(res, cb) {
647
+ var headers = {};
648
+ if (res && res.headers) {
649
+ headers = res.headers;
650
+ }
651
+ // handle digest auth
652
+ if (statusCode === 401 && headers['www-authenticate']
653
+ && !options.headers.authorization && args.digestAuth) {
654
+ var authenticate = headers['www-authenticate'];
655
+ if (authenticate.indexOf('Digest ') >= 0) {
656
+ debug('Request#%d %s: got digest auth header WWW-Authenticate: %s', reqId, url, authenticate);
657
+ options.headers.authorization = digestAuthHeader(options.method, options.path, authenticate, args.digestAuth);
658
+ debug('Request#%d %s: auth with digest header: %s', reqId, url, options.headers.authorization);
659
+ if (res.headers['set-cookie']) {
660
+ options.headers.cookie = res.headers['set-cookie'].join(';');
661
+ }
662
+ args.headers = options.headers;
663
+ exports.requestWithCallback(url, args, cb);
664
+ return true;
665
+ }
666
+ }
667
+ return false;
668
+ }
669
+
640
670
  function handleRedirect(res) {
641
671
  var err = null;
642
672
  if (args.followRedirect && statuses.redirect[res.statusCode]) { // handle redirect
@@ -740,6 +770,7 @@ function requestWithCallback(url, args, callback) {
740
770
  var result = handleRedirect(res);
741
771
  if (result.redirect) {
742
772
  res.resume();
773
+ createAndEmitResponseEvent(null, res);
743
774
  return;
744
775
  }
745
776
  if (result.error) {
@@ -781,6 +812,7 @@ function requestWithCallback(url, args, callback) {
781
812
  var result = handleRedirect(res);
782
813
  if (result.redirect) {
783
814
  res.resume();
815
+ createAndEmitResponseEvent(null, res);
784
816
  return;
785
817
  }
786
818
  if (result.error) {
@@ -874,6 +906,7 @@ function requestWithCallback(url, args, callback) {
874
906
  return done(result.error, body, res);
875
907
  }
876
908
  if (result.redirect) {
909
+ createAndEmitResponseEvent(null, res);
877
910
  return;
878
911
  }
879
912
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "urllib",
3
- "version": "2.37.0",
3
+ "version": "2.37.4",
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",
@@ -42,7 +42,7 @@
42
42
  "humanize-ms": "^1.2.0",
43
43
  "iconv-lite": "^0.4.15",
44
44
  "ip": "^1.1.5",
45
- "proxy-agent": "^3.1.0",
45
+ "proxy-agent": "^5.0.0",
46
46
  "pump": "^3.0.0",
47
47
  "qs": "^6.4.0",
48
48
  "statuses": "^1.3.1",