urllib 3.22.2 → 3.22.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/README.md CHANGED
@@ -68,7 +68,7 @@ console.log('status: %s, body size: %d, headers: %j', res.status, data.length, r
68
68
  - **keepAliveTimeout** `number | null` - Default is `4000`, 4 seconds - The timeout after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details.
69
69
  - ***auth*** String - `username:password` used in HTTP Basic Authorization.
70
70
  - ***digestAuth*** String - `username:password` used in HTTP [Digest Authorization](https://en.wikipedia.org/wiki/Digest_access_authentication).
71
- - ***followRedirect*** Boolean - follow HTTP 3xx responses as redirects. defaults to false.
71
+ - ***followRedirect*** Boolean - follow HTTP 3xx responses as redirects. defaults to true.
72
72
  - ***maxRedirects*** Number - The maximum number of redirects to follow, defaults to 10.
73
73
  - ***formatRedirectUrl*** Function - Format the redirect url by your self. Default is `url.resolve(from, to)`.
74
74
  - ***beforeRequest*** Function - Before request hook, you can change every thing here.
@@ -16,6 +16,7 @@ const node_path_1 = require("node:path");
16
16
  const node_fs_1 = require("node:fs");
17
17
  const node_url_1 = require("node:url");
18
18
  const node_perf_hooks_1 = require("node:perf_hooks");
19
+ const node_querystring_1 = __importDefault(require("node:querystring"));
19
20
  const undici_1 = require("undici");
20
21
  const symbols_js_1 = __importDefault(require("undici/lib/core/symbols.js"));
21
22
  const formdata_node_1 = require("formdata-node");
@@ -67,7 +68,7 @@ class BlobFromStream {
67
68
  return 'Blob';
68
69
  }
69
70
  }
70
- exports.HEADER_USER_AGENT = (0, default_user_agent_1.default)('node-urllib', '3.22.2');
71
+ exports.HEADER_USER_AGENT = (0, default_user_agent_1.default)('node-urllib', '3.22.4');
71
72
  function getFileName(stream) {
72
73
  const filePath = stream.path;
73
74
  if (filePath) {
@@ -159,7 +160,7 @@ class HttpClient extends node_events_1.EventEmitter {
159
160
  requestUrl = new URL(url.toString());
160
161
  }
161
162
  }
162
- const method = (options?.method ?? 'GET').toUpperCase();
163
+ const method = (options?.type || options?.method || 'GET').toUpperCase();
163
164
  const originalHeaders = options?.headers;
164
165
  const headers = {};
165
166
  const args = {
@@ -412,20 +413,16 @@ class HttpClient extends node_events_1.EventEmitter {
412
413
  || (0, utils_js_1.isReadable)(args.data);
413
414
  if (isGETOrHEAD) {
414
415
  if (!isStringOrBufferOrReadable) {
416
+ let query;
415
417
  if (args.nestedQuerystring) {
416
- const querystring = qs_1.default.stringify(args.data);
417
- // reset the requestUrl
418
- const href = requestUrl.href;
419
- requestUrl = new URL(href + (href.includes('?') ? '&' : '?') + querystring);
418
+ query = qs_1.default.stringify(args.data);
420
419
  }
421
420
  else {
422
- for (const field in args.data) {
423
- const fieldValue = args.data[field];
424
- if (fieldValue === undefined)
425
- continue;
426
- requestUrl.searchParams.append(field, fieldValue);
427
- }
421
+ query = node_querystring_1.default.stringify(args.data);
428
422
  }
423
+ // reset the requestUrl
424
+ const href = requestUrl.href;
425
+ requestUrl = new URL(href + (href.includes('?') ? '&' : '?') + query);
429
426
  }
430
427
  }
431
428
  else {
@@ -12,6 +12,8 @@ export type FixJSONCtlChars = boolean | FixJSONCtlCharsHandler;
12
12
  export type RequestOptions = {
13
13
  /** Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'. */
14
14
  method?: HttpMethod | Lowercase<HttpMethod>;
15
+ /** Alias for 'method'. */
16
+ type?: HttpMethod | Lowercase<HttpMethod>;
15
17
  /** Data to be sent. Will be stringify automatically. */
16
18
  data?: any;
17
19
  /** Manually set the content of payload. If set, data will be ignored. */
@@ -10,6 +10,7 @@ import { basename } from 'node:path';
10
10
  import { createReadStream } from 'node:fs';
11
11
  import { format as urlFormat } from 'node:url';
12
12
  import { performance } from 'node:perf_hooks';
13
+ import querystring from 'node:querystring';
13
14
  import { FormData as FormDataNative, request as undiciRequest, Agent, getGlobalDispatcher, } from 'undici';
14
15
  import undiciSymbols from 'undici/lib/core/symbols.js';
15
16
  import { FormData as FormDataNode } from 'formdata-node';
@@ -61,7 +62,7 @@ class BlobFromStream {
61
62
  return 'Blob';
62
63
  }
63
64
  }
64
- export const HEADER_USER_AGENT = createUserAgent('node-urllib', '3.22.2');
65
+ export const HEADER_USER_AGENT = createUserAgent('node-urllib', '3.22.4');
65
66
  function getFileName(stream) {
66
67
  const filePath = stream.path;
67
68
  if (filePath) {
@@ -153,7 +154,7 @@ export class HttpClient extends EventEmitter {
153
154
  requestUrl = new URL(url.toString());
154
155
  }
155
156
  }
156
- const method = (options?.method ?? 'GET').toUpperCase();
157
+ const method = (options?.type || options?.method || 'GET').toUpperCase();
157
158
  const originalHeaders = options?.headers;
158
159
  const headers = {};
159
160
  const args = {
@@ -406,20 +407,16 @@ export class HttpClient extends EventEmitter {
406
407
  || isReadable(args.data);
407
408
  if (isGETOrHEAD) {
408
409
  if (!isStringOrBufferOrReadable) {
410
+ let query;
409
411
  if (args.nestedQuerystring) {
410
- const querystring = qs.stringify(args.data);
411
- // reset the requestUrl
412
- const href = requestUrl.href;
413
- requestUrl = new URL(href + (href.includes('?') ? '&' : '?') + querystring);
412
+ query = qs.stringify(args.data);
414
413
  }
415
414
  else {
416
- for (const field in args.data) {
417
- const fieldValue = args.data[field];
418
- if (fieldValue === undefined)
419
- continue;
420
- requestUrl.searchParams.append(field, fieldValue);
421
- }
415
+ query = querystring.stringify(args.data);
422
416
  }
417
+ // reset the requestUrl
418
+ const href = requestUrl.href;
419
+ requestUrl = new URL(href + (href.includes('?') ? '&' : '?') + query);
423
420
  }
424
421
  }
425
422
  else {
@@ -12,6 +12,8 @@ export type FixJSONCtlChars = boolean | FixJSONCtlCharsHandler;
12
12
  export type RequestOptions = {
13
13
  /** Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'. */
14
14
  method?: HttpMethod | Lowercase<HttpMethod>;
15
+ /** Alias for 'method'. */
16
+ type?: HttpMethod | Lowercase<HttpMethod>;
15
17
  /** Data to be sent. Will be stringify automatically. */
16
18
  data?: any;
17
19
  /** Manually set the content of payload. If set, data will be ignored. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "urllib",
3
- "version": "3.22.2",
3
+ "version": "3.22.4",
4
4
  "publishConfig": {
5
5
  "tag": "latest"
6
6
  },
package/src/HttpClient.ts CHANGED
@@ -16,6 +16,7 @@ import { basename } from 'node:path';
16
16
  import { createReadStream } from 'node:fs';
17
17
  import { format as urlFormat } from 'node:url';
18
18
  import { performance } from 'node:perf_hooks';
19
+ import querystring from 'node:querystring';
19
20
  import {
20
21
  FormData as FormDataNative,
21
22
  request as undiciRequest,
@@ -255,7 +256,7 @@ export class HttpClient extends EventEmitter {
255
256
  }
256
257
  }
257
258
 
258
- const method = (options?.method ?? 'GET').toUpperCase() as HttpMethod;
259
+ const method = (options?.type || options?.method || 'GET').toUpperCase() as HttpMethod;
259
260
  const originalHeaders = options?.headers;
260
261
  const headers: IncomingHttpHeaders = {};
261
262
  const args = {
@@ -503,18 +504,15 @@ export class HttpClient extends EventEmitter {
503
504
  || isReadable(args.data);
504
505
  if (isGETOrHEAD) {
505
506
  if (!isStringOrBufferOrReadable) {
507
+ let query;
506
508
  if (args.nestedQuerystring) {
507
- const querystring = qs.stringify(args.data);
508
- // reset the requestUrl
509
- const href = requestUrl.href;
510
- requestUrl = new URL(href + (href.includes('?') ? '&' : '?') + querystring);
509
+ query = qs.stringify(args.data);
511
510
  } else {
512
- for (const field in args.data) {
513
- const fieldValue = args.data[field];
514
- if (fieldValue === undefined) continue;
515
- requestUrl.searchParams.append(field, fieldValue);
516
- }
511
+ query = querystring.stringify(args.data);
517
512
  }
513
+ // reset the requestUrl
514
+ const href = requestUrl.href;
515
+ requestUrl = new URL(href + (href.includes('?') ? '&' : '?') + query);
518
516
  }
519
517
  } else {
520
518
  if (isStringOrBufferOrReadable) {
package/src/Request.ts CHANGED
@@ -13,6 +13,8 @@ export type FixJSONCtlChars = boolean | FixJSONCtlCharsHandler;
13
13
  export type RequestOptions = {
14
14
  /** Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'. */
15
15
  method?: HttpMethod | Lowercase<HttpMethod>;
16
+ /** Alias for 'method'. */
17
+ type?: HttpMethod | Lowercase<HttpMethod>;
16
18
  /** Data to be sent. Will be stringify automatically. */
17
19
  data?: any;
18
20
  /** Manually set the content of payload. If set, data will be ignored. */