urllib 3.26.0 → 3.27.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.
@@ -1,6 +1,6 @@
1
1
  import { LookupFunction } from 'node:net';
2
2
  import { Agent, Dispatcher, buildConnector } from 'undici';
3
- export type CheckAddressFunction = (ip: string, family: number | string) => boolean;
3
+ export type CheckAddressFunction = (ip: string, family: number | string, hostname: string) => boolean;
4
4
  export type HttpAgentOptions = {
5
5
  lookup?: LookupFunction;
6
6
  checkAddress?: CheckAddressFunction;
@@ -36,14 +36,14 @@ class HttpAgent extends undici_1.Agent {
36
36
  if (options.checkAddress) {
37
37
  // dnsOptions.all set to default on Node.js >= 20, dns.lookup will return address array object
38
38
  if (typeof address === 'string') {
39
- if (!options.checkAddress(address, family)) {
39
+ if (!options.checkAddress(address, family, hostname)) {
40
40
  err = new IllegalAddressError(hostname, address, family);
41
41
  }
42
42
  }
43
43
  else if (Array.isArray(address)) {
44
44
  const addresses = address;
45
45
  for (const addr of addresses) {
46
- if (!options.checkAddress(addr.address, addr.family)) {
46
+ if (!options.checkAddress(addr.address, addr.family, hostname)) {
47
47
  err = new IllegalAddressError(hostname, addr.address, addr.family);
48
48
  break;
49
49
  }
@@ -69,7 +69,7 @@ class HttpAgent extends undici_1.Agent {
69
69
  const family = (0, node_net_1.isIP)(hostname);
70
70
  if (family === 4 || family === 6) {
71
71
  // if request hostname is ip, custom lookup won't execute
72
- if (!this.#checkAddress(hostname, family)) {
72
+ if (!this.#checkAddress(hostname, family, hostname)) {
73
73
  throw new IllegalAddressError(hostname, hostname, family);
74
74
  }
75
75
  }
@@ -68,7 +68,7 @@ class BlobFromStream {
68
68
  return 'Blob';
69
69
  }
70
70
  }
71
- exports.HEADER_USER_AGENT = (0, default_user_agent_1.default)('node-urllib', '3.26.0');
71
+ exports.HEADER_USER_AGENT = (0, default_user_agent_1.default)('node-urllib', '3.27.1');
72
72
  function getFileName(stream) {
73
73
  const filePath = stream.path;
74
74
  if (filePath) {
@@ -490,6 +490,8 @@ class HttpClient extends node_events_1.EventEmitter {
490
490
  // FIXME: merge exists cookie header
491
491
  requestOptions.headers.cookie = response.headers['set-cookie'].join(';');
492
492
  }
493
+ // Ensure the previous response is consumed as we re-use the same variable
494
+ await response.body.arrayBuffer();
493
495
  response = await (0, undici_1.request)(requestUrl, requestOptions);
494
496
  }
495
497
  }
@@ -1,6 +1,6 @@
1
1
  import { LookupFunction } from 'node:net';
2
2
  import { Agent, Dispatcher, buildConnector } from 'undici';
3
- export type CheckAddressFunction = (ip: string, family: number | string) => boolean;
3
+ export type CheckAddressFunction = (ip: string, family: number | string, hostname: string) => boolean;
4
4
  export type HttpAgentOptions = {
5
5
  lookup?: LookupFunction;
6
6
  checkAddress?: CheckAddressFunction;
@@ -30,14 +30,14 @@ export class HttpAgent extends Agent {
30
30
  if (options.checkAddress) {
31
31
  // dnsOptions.all set to default on Node.js >= 20, dns.lookup will return address array object
32
32
  if (typeof address === 'string') {
33
- if (!options.checkAddress(address, family)) {
33
+ if (!options.checkAddress(address, family, hostname)) {
34
34
  err = new IllegalAddressError(hostname, address, family);
35
35
  }
36
36
  }
37
37
  else if (Array.isArray(address)) {
38
38
  const addresses = address;
39
39
  for (const addr of addresses) {
40
- if (!options.checkAddress(addr.address, addr.family)) {
40
+ if (!options.checkAddress(addr.address, addr.family, hostname)) {
41
41
  err = new IllegalAddressError(hostname, addr.address, addr.family);
42
42
  break;
43
43
  }
@@ -63,7 +63,7 @@ export class HttpAgent extends Agent {
63
63
  const family = isIP(hostname);
64
64
  if (family === 4 || family === 6) {
65
65
  // if request hostname is ip, custom lookup won't execute
66
- if (!this.#checkAddress(hostname, family)) {
66
+ if (!this.#checkAddress(hostname, family, hostname)) {
67
67
  throw new IllegalAddressError(hostname, hostname, family);
68
68
  }
69
69
  }
@@ -62,7 +62,7 @@ class BlobFromStream {
62
62
  return 'Blob';
63
63
  }
64
64
  }
65
- export const HEADER_USER_AGENT = createUserAgent('node-urllib', '3.26.0');
65
+ export const HEADER_USER_AGENT = createUserAgent('node-urllib', '3.27.1');
66
66
  function getFileName(stream) {
67
67
  const filePath = stream.path;
68
68
  if (filePath) {
@@ -484,6 +484,8 @@ export class HttpClient extends EventEmitter {
484
484
  // FIXME: merge exists cookie header
485
485
  requestOptions.headers.cookie = response.headers['set-cookie'].join(';');
486
486
  }
487
+ // Ensure the previous response is consumed as we re-use the same variable
488
+ await response.body.arrayBuffer();
487
489
  response = await undiciRequest(requestUrl, requestOptions);
488
490
  }
489
491
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "urllib",
3
+ "version": "3.27.1"
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "urllib",
3
- "version": "3.26.0",
3
+ "version": "3.27.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -116,5 +116,6 @@
116
116
  "src"
117
117
  ],
118
118
  "types": "./dist/commonjs/index.d.ts",
119
- "main": "./dist/commonjs/index.js"
119
+ "main": "./dist/commonjs/index.js",
120
+ "module": "./dist/esm/index.js"
120
121
  }
package/src/HttpAgent.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  buildConnector,
7
7
  } from 'undici';
8
8
 
9
- export type CheckAddressFunction = (ip: string, family: number | string) => boolean;
9
+ export type CheckAddressFunction = (ip: string, family: number | string, hostname: string) => boolean;
10
10
 
11
11
  export type HttpAgentOptions = {
12
12
  lookup?: LookupFunction;
@@ -46,13 +46,13 @@ export class HttpAgent extends Agent {
46
46
  if (options.checkAddress) {
47
47
  // dnsOptions.all set to default on Node.js >= 20, dns.lookup will return address array object
48
48
  if (typeof address === 'string') {
49
- if (!options.checkAddress(address, family)) {
49
+ if (!options.checkAddress(address, family, hostname)) {
50
50
  err = new IllegalAddressError(hostname, address, family);
51
51
  }
52
52
  } else if (Array.isArray(address)) {
53
53
  const addresses = address as { address: string, family: number }[];
54
54
  for (const addr of addresses) {
55
- if (!options.checkAddress(addr.address, addr.family)) {
55
+ if (!options.checkAddress(addr.address, addr.family, hostname)) {
56
56
  err = new IllegalAddressError(hostname, addr.address, addr.family);
57
57
  break;
58
58
  }
@@ -79,7 +79,7 @@ export class HttpAgent extends Agent {
79
79
  const family = isIP(hostname);
80
80
  if (family === 4 || family === 6) {
81
81
  // if request hostname is ip, custom lookup won't execute
82
- if (!this.#checkAddress(hostname, family)) {
82
+ if (!this.#checkAddress(hostname, family, hostname)) {
83
83
  throw new IllegalAddressError(hostname, hostname, family);
84
84
  }
85
85
  }
package/src/HttpClient.ts CHANGED
@@ -581,6 +581,8 @@ export class HttpClient extends EventEmitter {
581
581
  // FIXME: merge exists cookie header
582
582
  requestOptions.headers.cookie = response.headers['set-cookie'].join(';');
583
583
  }
584
+ // Ensure the previous response is consumed as we re-use the same variable
585
+ await response.body.arrayBuffer();
584
586
  response = await undiciRequest(requestUrl, requestOptions as UndiciRequestOption);
585
587
  }
586
588
  }