rezo 1.0.12 → 1.0.14

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.
Files changed (44) hide show
  1. package/dist/adapters/curl.cjs +89 -22
  2. package/dist/adapters/curl.js +89 -22
  3. package/dist/adapters/entries/curl.d.ts +8 -0
  4. package/dist/adapters/entries/fetch.d.ts +8 -0
  5. package/dist/adapters/entries/http.d.ts +8 -0
  6. package/dist/adapters/entries/http2.d.ts +8 -0
  7. package/dist/adapters/entries/react-native.d.ts +8 -0
  8. package/dist/adapters/entries/xhr.d.ts +8 -0
  9. package/dist/adapters/fetch.cjs +128 -58
  10. package/dist/adapters/fetch.js +128 -58
  11. package/dist/adapters/http.cjs +43 -13
  12. package/dist/adapters/http.js +43 -13
  13. package/dist/adapters/http2.cjs +136 -58
  14. package/dist/adapters/http2.js +136 -58
  15. package/dist/adapters/index.cjs +6 -6
  16. package/dist/cache/index.cjs +13 -13
  17. package/dist/core/rezo.cjs +27 -6
  18. package/dist/core/rezo.js +27 -6
  19. package/dist/crawler.d.ts +8 -0
  20. package/dist/entries/crawler.cjs +5 -5
  21. package/dist/index.cjs +24 -24
  22. package/dist/index.d.ts +8 -0
  23. package/dist/platform/browser.d.ts +8 -0
  24. package/dist/platform/bun.d.ts +8 -0
  25. package/dist/platform/deno.d.ts +8 -0
  26. package/dist/platform/node.d.ts +8 -0
  27. package/dist/platform/react-native.d.ts +8 -0
  28. package/dist/platform/worker.d.ts +8 -0
  29. package/dist/plugin/index.cjs +36 -36
  30. package/dist/proxy/index.cjs +2 -2
  31. package/dist/queue/index.cjs +8 -8
  32. package/dist/responses/buildError.cjs +5 -1
  33. package/dist/responses/buildError.js +5 -1
  34. package/dist/responses/buildResponse.cjs +2 -0
  35. package/dist/responses/buildResponse.js +2 -0
  36. package/dist/utils/compression.cjs +6 -6
  37. package/dist/utils/compression.js +6 -6
  38. package/dist/utils/form-data.cjs +64 -7
  39. package/dist/utils/form-data.js +64 -7
  40. package/dist/utils/headers.cjs +17 -0
  41. package/dist/utils/headers.js +17 -1
  42. package/dist/utils/http-config.cjs +39 -4
  43. package/dist/utils/http-config.js +39 -4
  44. package/package.json +1 -1
@@ -314,11 +314,19 @@ export declare class RezoFormData extends NodeFormData {
314
314
  toBuffer(): Buffer;
315
315
  /**
316
316
  * Create RezoFormData from object
317
+ * Properly handles nested objects by JSON.stringify-ing them
317
318
  * @param {Record<string, any>} obj - Object to convert
318
319
  * @param {Options} options - Optional RezoFormData options
319
320
  * @returns {RezoFormData}
320
321
  */
321
322
  static fromObject(obj: Record<string, any>, options?: Options): RezoFormData;
323
+ /**
324
+ * Helper to append a value to FormData with proper type handling
325
+ * @param {RezoFormData} formData - The form data to append to
326
+ * @param {string} key - The field name
327
+ * @param {any} value - The value to append
328
+ */
329
+ private static appendValue;
322
330
  /**
323
331
  * Convert to URL query string
324
332
  * Warning: File, Blob, and binary data will be omitted
@@ -314,11 +314,19 @@ export declare class RezoFormData extends NodeFormData {
314
314
  toBuffer(): Buffer;
315
315
  /**
316
316
  * Create RezoFormData from object
317
+ * Properly handles nested objects by JSON.stringify-ing them
317
318
  * @param {Record<string, any>} obj - Object to convert
318
319
  * @param {Options} options - Optional RezoFormData options
319
320
  * @returns {RezoFormData}
320
321
  */
321
322
  static fromObject(obj: Record<string, any>, options?: Options): RezoFormData;
323
+ /**
324
+ * Helper to append a value to FormData with proper type handling
325
+ * @param {RezoFormData} formData - The form data to append to
326
+ * @param {string} key - The field name
327
+ * @param {any} value - The value to append
328
+ */
329
+ private static appendValue;
322
330
  /**
323
331
  * Convert to URL query string
324
332
  * Warning: File, Blob, and binary data will be omitted
@@ -314,11 +314,19 @@ export declare class RezoFormData extends NodeFormData {
314
314
  toBuffer(): Buffer;
315
315
  /**
316
316
  * Create RezoFormData from object
317
+ * Properly handles nested objects by JSON.stringify-ing them
317
318
  * @param {Record<string, any>} obj - Object to convert
318
319
  * @param {Options} options - Optional RezoFormData options
319
320
  * @returns {RezoFormData}
320
321
  */
321
322
  static fromObject(obj: Record<string, any>, options?: Options): RezoFormData;
323
+ /**
324
+ * Helper to append a value to FormData with proper type handling
325
+ * @param {RezoFormData} formData - The form data to append to
326
+ * @param {string} key - The field name
327
+ * @param {any} value - The value to append
328
+ */
329
+ private static appendValue;
322
330
  /**
323
331
  * Convert to URL query string
324
332
  * Warning: File, Blob, and binary data will be omitted
@@ -314,11 +314,19 @@ export declare class RezoFormData extends NodeFormData {
314
314
  toBuffer(): Buffer;
315
315
  /**
316
316
  * Create RezoFormData from object
317
+ * Properly handles nested objects by JSON.stringify-ing them
317
318
  * @param {Record<string, any>} obj - Object to convert
318
319
  * @param {Options} options - Optional RezoFormData options
319
320
  * @returns {RezoFormData}
320
321
  */
321
322
  static fromObject(obj: Record<string, any>, options?: Options): RezoFormData;
323
+ /**
324
+ * Helper to append a value to FormData with proper type handling
325
+ * @param {RezoFormData} formData - The form data to append to
326
+ * @param {string} key - The field name
327
+ * @param {any} value - The value to append
328
+ */
329
+ private static appendValue;
322
330
  /**
323
331
  * Convert to URL query string
324
332
  * Warning: File, Blob, and binary data will be omitted
@@ -1,36 +1,36 @@
1
- const _mod_a9kn57 = require('./crawler.cjs');
2
- exports.Crawler = _mod_a9kn57.Crawler;;
3
- const _mod_6ccm6s = require('./crawler-options.cjs');
4
- exports.CrawlerOptions = _mod_6ccm6s.CrawlerOptions;;
5
- const _mod_7naagm = require('../cache/file-cacher.cjs');
6
- exports.FileCacher = _mod_7naagm.FileCacher;;
7
- const _mod_22i2ua = require('../cache/url-store.cjs');
8
- exports.UrlStore = _mod_22i2ua.UrlStore;;
9
- const _mod_37jf5t = require('./addon/oxylabs/index.cjs');
10
- exports.Oxylabs = _mod_37jf5t.Oxylabs;;
11
- const _mod_u1lbrx = require('./addon/oxylabs/options.cjs');
12
- exports.OXYLABS_BROWSER_TYPES = _mod_u1lbrx.OXYLABS_BROWSER_TYPES;
13
- exports.OXYLABS_COMMON_LOCALES = _mod_u1lbrx.OXYLABS_COMMON_LOCALES;
14
- exports.OXYLABS_COMMON_GEO_LOCATIONS = _mod_u1lbrx.OXYLABS_COMMON_GEO_LOCATIONS;
15
- exports.OXYLABS_US_STATES = _mod_u1lbrx.OXYLABS_US_STATES;
16
- exports.OXYLABS_EUROPEAN_COUNTRIES = _mod_u1lbrx.OXYLABS_EUROPEAN_COUNTRIES;
17
- exports.OXYLABS_ASIAN_COUNTRIES = _mod_u1lbrx.OXYLABS_ASIAN_COUNTRIES;
18
- exports.getRandomOxylabsBrowserType = _mod_u1lbrx.getRandomBrowserType;
19
- exports.getRandomOxylabsLocale = _mod_u1lbrx.getRandomLocale;
20
- exports.getRandomOxylabsGeoLocation = _mod_u1lbrx.getRandomGeoLocation;;
21
- const _mod_mozpwt = require('./addon/decodo/index.cjs');
22
- exports.Decodo = _mod_mozpwt.Decodo;;
23
- const _mod_g6f0a3 = require('./addon/decodo/options.cjs');
24
- exports.DECODO_DEVICE_TYPES = _mod_g6f0a3.DECODO_DEVICE_TYPES;
25
- exports.DECODO_HEADLESS_MODES = _mod_g6f0a3.DECODO_HEADLESS_MODES;
26
- exports.DECODO_COMMON_LOCALES = _mod_g6f0a3.DECODO_COMMON_LOCALES;
27
- exports.DECODO_COMMON_COUNTRIES = _mod_g6f0a3.DECODO_COMMON_COUNTRIES;
28
- exports.DECODO_EUROPEAN_COUNTRIES = _mod_g6f0a3.DECODO_EUROPEAN_COUNTRIES;
29
- exports.DECODO_ASIAN_COUNTRIES = _mod_g6f0a3.DECODO_ASIAN_COUNTRIES;
30
- exports.DECODO_US_STATES = _mod_g6f0a3.DECODO_US_STATES;
31
- exports.DECODO_COMMON_CITIES = _mod_g6f0a3.DECODO_COMMON_CITIES;
32
- exports.getRandomDecodoDeviceType = _mod_g6f0a3.getRandomDeviceType;
33
- exports.getRandomDecodoLocale = _mod_g6f0a3.getRandomLocale;
34
- exports.getRandomDecodoCountry = _mod_g6f0a3.getRandomCountry;
35
- exports.getRandomDecodoCity = _mod_g6f0a3.getRandomCity;
36
- exports.generateDecodoSessionId = _mod_g6f0a3.generateSessionId;;
1
+ const _mod_61gqt8 = require('./crawler.cjs');
2
+ exports.Crawler = _mod_61gqt8.Crawler;;
3
+ const _mod_s20ywb = require('./crawler-options.cjs');
4
+ exports.CrawlerOptions = _mod_s20ywb.CrawlerOptions;;
5
+ const _mod_slgnf8 = require('../cache/file-cacher.cjs');
6
+ exports.FileCacher = _mod_slgnf8.FileCacher;;
7
+ const _mod_jvu3uj = require('../cache/url-store.cjs');
8
+ exports.UrlStore = _mod_jvu3uj.UrlStore;;
9
+ const _mod_v2pwhj = require('./addon/oxylabs/index.cjs');
10
+ exports.Oxylabs = _mod_v2pwhj.Oxylabs;;
11
+ const _mod_lxafyd = require('./addon/oxylabs/options.cjs');
12
+ exports.OXYLABS_BROWSER_TYPES = _mod_lxafyd.OXYLABS_BROWSER_TYPES;
13
+ exports.OXYLABS_COMMON_LOCALES = _mod_lxafyd.OXYLABS_COMMON_LOCALES;
14
+ exports.OXYLABS_COMMON_GEO_LOCATIONS = _mod_lxafyd.OXYLABS_COMMON_GEO_LOCATIONS;
15
+ exports.OXYLABS_US_STATES = _mod_lxafyd.OXYLABS_US_STATES;
16
+ exports.OXYLABS_EUROPEAN_COUNTRIES = _mod_lxafyd.OXYLABS_EUROPEAN_COUNTRIES;
17
+ exports.OXYLABS_ASIAN_COUNTRIES = _mod_lxafyd.OXYLABS_ASIAN_COUNTRIES;
18
+ exports.getRandomOxylabsBrowserType = _mod_lxafyd.getRandomBrowserType;
19
+ exports.getRandomOxylabsLocale = _mod_lxafyd.getRandomLocale;
20
+ exports.getRandomOxylabsGeoLocation = _mod_lxafyd.getRandomGeoLocation;;
21
+ const _mod_wknbgy = require('./addon/decodo/index.cjs');
22
+ exports.Decodo = _mod_wknbgy.Decodo;;
23
+ const _mod_wp7ex5 = require('./addon/decodo/options.cjs');
24
+ exports.DECODO_DEVICE_TYPES = _mod_wp7ex5.DECODO_DEVICE_TYPES;
25
+ exports.DECODO_HEADLESS_MODES = _mod_wp7ex5.DECODO_HEADLESS_MODES;
26
+ exports.DECODO_COMMON_LOCALES = _mod_wp7ex5.DECODO_COMMON_LOCALES;
27
+ exports.DECODO_COMMON_COUNTRIES = _mod_wp7ex5.DECODO_COMMON_COUNTRIES;
28
+ exports.DECODO_EUROPEAN_COUNTRIES = _mod_wp7ex5.DECODO_EUROPEAN_COUNTRIES;
29
+ exports.DECODO_ASIAN_COUNTRIES = _mod_wp7ex5.DECODO_ASIAN_COUNTRIES;
30
+ exports.DECODO_US_STATES = _mod_wp7ex5.DECODO_US_STATES;
31
+ exports.DECODO_COMMON_CITIES = _mod_wp7ex5.DECODO_COMMON_CITIES;
32
+ exports.getRandomDecodoDeviceType = _mod_wp7ex5.getRandomDeviceType;
33
+ exports.getRandomDecodoLocale = _mod_wp7ex5.getRandomLocale;
34
+ exports.getRandomDecodoCountry = _mod_wp7ex5.getRandomCountry;
35
+ exports.getRandomDecodoCity = _mod_wp7ex5.getRandomCity;
36
+ exports.generateDecodoSessionId = _mod_wp7ex5.generateSessionId;;
@@ -1,8 +1,8 @@
1
1
  const { SocksProxyAgent: RezoSocksProxy } = require("socks-proxy-agent");
2
2
  const { HttpsProxyAgent: RezoHttpsSocks } = require("https-proxy-agent");
3
3
  const { HttpProxyAgent: RezoHttpSocks } = require("http-proxy-agent");
4
- const _mod_448ob0 = require('./manager.cjs');
5
- exports.ProxyManager = _mod_448ob0.ProxyManager;;
4
+ const _mod_c6k1hi = require('./manager.cjs');
5
+ exports.ProxyManager = _mod_c6k1hi.ProxyManager;;
6
6
  function createOptions(uri, opts) {
7
7
  if (uri instanceof URL || typeof uri === "string") {
8
8
  return {
@@ -1,8 +1,8 @@
1
- const _mod_ipfe1q = require('./queue.cjs');
2
- exports.RezoQueue = _mod_ipfe1q.RezoQueue;;
3
- const _mod_sc99zf = require('./http-queue.cjs');
4
- exports.HttpQueue = _mod_sc99zf.HttpQueue;
5
- exports.extractDomain = _mod_sc99zf.extractDomain;;
6
- const _mod_4akyyt = require('./types.cjs');
7
- exports.Priority = _mod_4akyyt.Priority;
8
- exports.HttpMethodPriority = _mod_4akyyt.HttpMethodPriority;;
1
+ const _mod_ywac6g = require('./queue.cjs');
2
+ exports.RezoQueue = _mod_ywac6g.RezoQueue;;
3
+ const _mod_id4rdx = require('./http-queue.cjs');
4
+ exports.HttpQueue = _mod_id4rdx.HttpQueue;
5
+ exports.extractDomain = _mod_id4rdx.extractDomain;;
6
+ const _mod_dnemth = require('./types.cjs');
7
+ exports.Priority = _mod_dnemth.Priority;
8
+ exports.HttpMethodPriority = _mod_dnemth.HttpMethodPriority;;
@@ -348,7 +348,11 @@ function buildRedirectError(messageOrParams, config, request, response) {
348
348
  return RezoError.createRedirectError("Redirect location not found", errorConfig, errorRequest, errorResponse);
349
349
  }
350
350
  function builErrorFromResponse(message, response, config, request) {
351
- return RezoError.createRedirectError(message, config, request, response);
351
+ const statusCode = response?.status || 0;
352
+ if (statusCode >= 400) {
353
+ return RezoError.createHttpError(statusCode, config, request, response);
354
+ }
355
+ return new RezoError(message, config, "REZ_UNKNOWN_ERROR", request, response);
352
356
  }
353
357
  function buildNetworkError(message, code, config, request) {
354
358
  return RezoError.createNetworkError(message, code, config, request);
@@ -348,7 +348,11 @@ export function buildRedirectError(messageOrParams, config, request, response) {
348
348
  return RezoError.createRedirectError("Redirect location not found", errorConfig, errorRequest, errorResponse);
349
349
  }
350
350
  export function builErrorFromResponse(message, response, config, request) {
351
- return RezoError.createRedirectError(message, config, request, response);
351
+ const statusCode = response?.status || 0;
352
+ if (statusCode >= 400) {
353
+ return RezoError.createHttpError(statusCode, config, request, response);
354
+ }
355
+ return new RezoError(message, config, "REZ_UNKNOWN_ERROR", request, response);
352
356
  }
353
357
  export function buildNetworkError(message, code, config, request) {
354
358
  return RezoError.createNetworkError(message, code, config, request);
@@ -339,6 +339,8 @@ function buildResponse(params) {
339
339
  setCookiesString: []
340
340
  };
341
341
  }
342
+ config.status = statusCode;
343
+ config.statusText = statusMessage;
342
344
  return {
343
345
  data: formatResponse(body, config, rezoHeaders),
344
346
  status: statusCode,
@@ -339,6 +339,8 @@ export function buildResponse(params) {
339
339
  setCookiesString: []
340
340
  };
341
341
  }
342
+ config.status = statusCode;
343
+ config.statusText = statusMessage;
342
344
  return {
343
345
  data: formatResponse(body, config, rezoHeaders),
344
346
  status: statusCode,
@@ -50,16 +50,16 @@ class CompressionUtil {
50
50
  if (!config) {
51
51
  return true;
52
52
  }
53
+ if (config.decompress === false) {
54
+ return false;
55
+ }
53
56
  if (config.compression?.enabled === false) {
54
57
  return false;
55
58
  }
56
- if (config.compression?.enabled === undefined) {
57
- if (config.compression?.algorithms) {
58
- return config.compression.algorithms.includes(contentEncoding.toLowerCase());
59
- }
60
- return true;
59
+ if (config.compression?.algorithms) {
60
+ return config.compression.algorithms.includes(contentEncoding.toLowerCase());
61
61
  }
62
- return config.compression.enabled;
62
+ return true;
63
63
  }
64
64
  static createZstdDecompressStream(response) {
65
65
  const decompressor = getZstdDecompressor();
@@ -50,16 +50,16 @@ export class CompressionUtil {
50
50
  if (!config) {
51
51
  return true;
52
52
  }
53
+ if (config.decompress === false) {
54
+ return false;
55
+ }
53
56
  if (config.compression?.enabled === false) {
54
57
  return false;
55
58
  }
56
- if (config.compression?.enabled === undefined) {
57
- if (config.compression?.algorithms) {
58
- return config.compression.algorithms.includes(contentEncoding.toLowerCase());
59
- }
60
- return true;
59
+ if (config.compression?.algorithms) {
60
+ return config.compression.algorithms.includes(contentEncoding.toLowerCase());
61
61
  }
62
- return config.compression.enabled;
62
+ return true;
63
63
  }
64
64
  static createZstdDecompressStream(response) {
65
65
  const decompressor = getZstdDecompressor();
@@ -71,16 +71,73 @@ class RezoFormData extends NodeFormData {
71
71
  static fromObject(obj, options) {
72
72
  const formData = new RezoFormData(options);
73
73
  for (const [key, value] of Object.entries(obj)) {
74
- if (Array.isArray(value)) {
75
- for (const item of value) {
76
- formData.append(key, item);
77
- }
78
- } else {
79
- formData.append(key, value);
80
- }
74
+ RezoFormData.appendValue(formData, key, value);
81
75
  }
82
76
  return formData;
83
77
  }
78
+ static appendValue(formData, key, value) {
79
+ if (value === null || value === undefined) {
80
+ return;
81
+ }
82
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
83
+ formData.append(key, String(value));
84
+ return;
85
+ }
86
+ if (Buffer.isBuffer(value)) {
87
+ formData.append(key, value, {
88
+ contentType: "application/octet-stream"
89
+ });
90
+ return;
91
+ }
92
+ if (value instanceof Uint8Array) {
93
+ formData.append(key, Buffer.from(value), {
94
+ contentType: "application/octet-stream"
95
+ });
96
+ return;
97
+ }
98
+ if (value instanceof Readable) {
99
+ formData.append(key, value);
100
+ return;
101
+ }
102
+ if (typeof File !== "undefined" && value instanceof File) {
103
+ formData.append(key, value, {
104
+ filename: value.name,
105
+ contentType: value.type || "application/octet-stream"
106
+ });
107
+ return;
108
+ }
109
+ if (typeof Blob !== "undefined" && value instanceof Blob) {
110
+ formData.append(key, value, {
111
+ contentType: value.type || "application/octet-stream"
112
+ });
113
+ return;
114
+ }
115
+ if (Array.isArray(value)) {
116
+ for (const item of value) {
117
+ RezoFormData.appendValue(formData, key, item);
118
+ }
119
+ return;
120
+ }
121
+ if (typeof value === "object" && value !== null && "value" in value && (value.filename || value.contentType)) {
122
+ const opts = {};
123
+ if (value.filename)
124
+ opts.filename = value.filename;
125
+ if (value.contentType)
126
+ opts.contentType = value.contentType;
127
+ formData.append(key, value.value, opts);
128
+ return;
129
+ }
130
+ if (typeof value === "object" && value !== null) {
131
+ const jsonString = JSON.stringify(value);
132
+ const jsonBuffer = Buffer.from(jsonString, "utf8");
133
+ formData.append(key, jsonBuffer, {
134
+ filename: `${key}.json`,
135
+ contentType: "application/json"
136
+ });
137
+ return;
138
+ }
139
+ formData.append(key, String(value));
140
+ }
84
141
  async toUrlQueryString(convertBinaryToBase64 = false) {
85
142
  const params = new URLSearchParams;
86
143
  let hasOmittedData = false;
@@ -71,16 +71,73 @@ export class RezoFormData extends NodeFormData {
71
71
  static fromObject(obj, options) {
72
72
  const formData = new RezoFormData(options);
73
73
  for (const [key, value] of Object.entries(obj)) {
74
- if (Array.isArray(value)) {
75
- for (const item of value) {
76
- formData.append(key, item);
77
- }
78
- } else {
79
- formData.append(key, value);
80
- }
74
+ RezoFormData.appendValue(formData, key, value);
81
75
  }
82
76
  return formData;
83
77
  }
78
+ static appendValue(formData, key, value) {
79
+ if (value === null || value === undefined) {
80
+ return;
81
+ }
82
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
83
+ formData.append(key, String(value));
84
+ return;
85
+ }
86
+ if (Buffer.isBuffer(value)) {
87
+ formData.append(key, value, {
88
+ contentType: "application/octet-stream"
89
+ });
90
+ return;
91
+ }
92
+ if (value instanceof Uint8Array) {
93
+ formData.append(key, Buffer.from(value), {
94
+ contentType: "application/octet-stream"
95
+ });
96
+ return;
97
+ }
98
+ if (value instanceof Readable) {
99
+ formData.append(key, value);
100
+ return;
101
+ }
102
+ if (typeof File !== "undefined" && value instanceof File) {
103
+ formData.append(key, value, {
104
+ filename: value.name,
105
+ contentType: value.type || "application/octet-stream"
106
+ });
107
+ return;
108
+ }
109
+ if (typeof Blob !== "undefined" && value instanceof Blob) {
110
+ formData.append(key, value, {
111
+ contentType: value.type || "application/octet-stream"
112
+ });
113
+ return;
114
+ }
115
+ if (Array.isArray(value)) {
116
+ for (const item of value) {
117
+ RezoFormData.appendValue(formData, key, item);
118
+ }
119
+ return;
120
+ }
121
+ if (typeof value === "object" && value !== null && "value" in value && (value.filename || value.contentType)) {
122
+ const opts = {};
123
+ if (value.filename)
124
+ opts.filename = value.filename;
125
+ if (value.contentType)
126
+ opts.contentType = value.contentType;
127
+ formData.append(key, value.value, opts);
128
+ return;
129
+ }
130
+ if (typeof value === "object" && value !== null) {
131
+ const jsonString = JSON.stringify(value);
132
+ const jsonBuffer = Buffer.from(jsonString, "utf8");
133
+ formData.append(key, jsonBuffer, {
134
+ filename: `${key}.json`,
135
+ contentType: "application/json"
136
+ });
137
+ return;
138
+ }
139
+ formData.append(key, String(value));
140
+ }
84
141
  async toUrlQueryString(convertBinaryToBase64 = false) {
85
142
  const params = new URLSearchParams;
86
143
  let hasOmittedData = false;
@@ -156,7 +156,24 @@ class RezoHeaders extends Headers {
156
156
  return "RezoHeaders";
157
157
  }
158
158
  }
159
+ function sanitizeHttp2Headers(headers) {
160
+ const result = {};
161
+ for (const key of Reflect.ownKeys(headers)) {
162
+ if (typeof key === "symbol")
163
+ continue;
164
+ if (key.startsWith(":"))
165
+ continue;
166
+ const value = headers[key];
167
+ if (typeof value === "string") {
168
+ result[key] = value;
169
+ } else if (Array.isArray(value)) {
170
+ result[key] = value.join(", ");
171
+ }
172
+ }
173
+ return result;
174
+ }
159
175
 
160
176
  exports.RezoHeaders = RezoHeaders;
177
+ exports.sanitizeHttp2Headers = sanitizeHttp2Headers;
161
178
  exports.default = RezoHeaders;
162
179
  module.exports = Object.assign(RezoHeaders, exports);
@@ -156,6 +156,22 @@ class RezoHeaders extends Headers {
156
156
  return "RezoHeaders";
157
157
  }
158
158
  }
159
+ function sanitizeHttp2Headers(headers) {
160
+ const result = {};
161
+ for (const key of Reflect.ownKeys(headers)) {
162
+ if (typeof key === "symbol")
163
+ continue;
164
+ if (key.startsWith(":"))
165
+ continue;
166
+ const value = headers[key];
167
+ if (typeof value === "string") {
168
+ result[key] = value;
169
+ } else if (Array.isArray(value)) {
170
+ result[key] = value.join(", ");
171
+ }
172
+ }
173
+ return result;
174
+ }
159
175
 
160
- export { RezoHeaders };
176
+ export { RezoHeaders, sanitizeHttp2Headers };
161
177
  export default RezoHeaders;
@@ -196,7 +196,8 @@ async function getDefaultConfig(config = {}, proxyManager) {
196
196
  hooks: config.hooks,
197
197
  cookieFile: config.cookieFile,
198
198
  encoding: config.encoding,
199
- proxyManager: proxyManager || null
199
+ proxyManager: proxyManager || null,
200
+ decompress: config.decompress
200
201
  };
201
202
  }
202
203
  async function getFS() {
@@ -308,7 +309,23 @@ function prepareHTTPOptions(options, jar, addedOptions, config) {
308
309
  const _body = options.formData || options.multipart;
309
310
  if (_body) {
310
311
  Object.entries(_body).forEach(([key, value]) => {
311
- body.append(key, value);
312
+ if (value === null || value === undefined) {
313
+ body.append(key, "");
314
+ } else if (typeof value === "string" || Buffer.isBuffer(value)) {
315
+ body.append(key, value);
316
+ } else if (typeof value === "object" && typeof value.pipe === "function") {
317
+ body.append(key, value);
318
+ } else if (typeof value === "object" && value.value !== undefined) {
319
+ const val = value.value;
320
+ const opts = value.options || {};
321
+ if (typeof val === "string" || Buffer.isBuffer(val)) {
322
+ body.append(key, val, opts);
323
+ } else {
324
+ body.append(key, String(val), opts);
325
+ }
326
+ } else {
327
+ body.append(key, String(value));
328
+ }
312
329
  });
313
330
  }
314
331
  contentType = body.getContentType();
@@ -344,7 +361,23 @@ function prepareHTTPOptions(options, jar, addedOptions, config) {
344
361
  if (fetchOptions.body && typeof fetchOptions.body === "object") {
345
362
  const formData = new RezoFormData;
346
363
  Object.entries(fetchOptions.body).forEach(([key, value]) => {
347
- formData.append(key, value);
364
+ if (value === null || value === undefined) {
365
+ formData.append(key, "");
366
+ } else if (typeof value === "string" || Buffer.isBuffer(value)) {
367
+ formData.append(key, value);
368
+ } else if (typeof value === "object" && typeof value.pipe === "function") {
369
+ formData.append(key, value);
370
+ } else if (typeof value === "object" && value.value !== undefined) {
371
+ const val = value.value;
372
+ const opts = value.options || {};
373
+ if (typeof val === "string" || Buffer.isBuffer(val)) {
374
+ formData.append(key, val, opts);
375
+ } else {
376
+ formData.append(key, String(val), opts);
377
+ }
378
+ } else {
379
+ formData.append(key, String(value));
380
+ }
348
381
  });
349
382
  fetchOptions.body = formData;
350
383
  }
@@ -544,10 +577,12 @@ As a workaround, process.env.NODE_TLS_REJECT_UNAUTHORIZED is being set to '0'.
544
577
  redirectHistory: [],
545
578
  network: {},
546
579
  timing: {},
580
+ transfer: {},
547
581
  responseType: requestOptions.responseType,
548
582
  proxy: normalizedProxy,
549
583
  enableRedirectCycleDetection,
550
- rejectUnauthorized: typeof rejectUnauthorized === "boolean" ? rejectUnauthorized : true
584
+ rejectUnauthorized: typeof rejectUnauthorized === "boolean" ? rejectUnauthorized : true,
585
+ decompress: typeof requestOptions.decompress === "boolean" ? requestOptions.decompress : typeof defaultOptions.decompress === "boolean" ? defaultOptions.decompress : true
551
586
  };
552
587
  config.setSignal = setSignal.bind(config);
553
588
  if (requestOptions.encoding || defaultOptions.encoding) {
@@ -196,7 +196,8 @@ export async function getDefaultConfig(config = {}, proxyManager) {
196
196
  hooks: config.hooks,
197
197
  cookieFile: config.cookieFile,
198
198
  encoding: config.encoding,
199
- proxyManager: proxyManager || null
199
+ proxyManager: proxyManager || null,
200
+ decompress: config.decompress
200
201
  };
201
202
  }
202
203
  export async function getFS() {
@@ -308,7 +309,23 @@ export function prepareHTTPOptions(options, jar, addedOptions, config) {
308
309
  const _body = options.formData || options.multipart;
309
310
  if (_body) {
310
311
  Object.entries(_body).forEach(([key, value]) => {
311
- body.append(key, value);
312
+ if (value === null || value === undefined) {
313
+ body.append(key, "");
314
+ } else if (typeof value === "string" || Buffer.isBuffer(value)) {
315
+ body.append(key, value);
316
+ } else if (typeof value === "object" && typeof value.pipe === "function") {
317
+ body.append(key, value);
318
+ } else if (typeof value === "object" && value.value !== undefined) {
319
+ const val = value.value;
320
+ const opts = value.options || {};
321
+ if (typeof val === "string" || Buffer.isBuffer(val)) {
322
+ body.append(key, val, opts);
323
+ } else {
324
+ body.append(key, String(val), opts);
325
+ }
326
+ } else {
327
+ body.append(key, String(value));
328
+ }
312
329
  });
313
330
  }
314
331
  contentType = body.getContentType();
@@ -344,7 +361,23 @@ export function prepareHTTPOptions(options, jar, addedOptions, config) {
344
361
  if (fetchOptions.body && typeof fetchOptions.body === "object") {
345
362
  const formData = new RezoFormData;
346
363
  Object.entries(fetchOptions.body).forEach(([key, value]) => {
347
- formData.append(key, value);
364
+ if (value === null || value === undefined) {
365
+ formData.append(key, "");
366
+ } else if (typeof value === "string" || Buffer.isBuffer(value)) {
367
+ formData.append(key, value);
368
+ } else if (typeof value === "object" && typeof value.pipe === "function") {
369
+ formData.append(key, value);
370
+ } else if (typeof value === "object" && value.value !== undefined) {
371
+ const val = value.value;
372
+ const opts = value.options || {};
373
+ if (typeof val === "string" || Buffer.isBuffer(val)) {
374
+ formData.append(key, val, opts);
375
+ } else {
376
+ formData.append(key, String(val), opts);
377
+ }
378
+ } else {
379
+ formData.append(key, String(value));
380
+ }
348
381
  });
349
382
  fetchOptions.body = formData;
350
383
  }
@@ -544,10 +577,12 @@ As a workaround, process.env.NODE_TLS_REJECT_UNAUTHORIZED is being set to '0'.
544
577
  redirectHistory: [],
545
578
  network: {},
546
579
  timing: {},
580
+ transfer: {},
547
581
  responseType: requestOptions.responseType,
548
582
  proxy: normalizedProxy,
549
583
  enableRedirectCycleDetection,
550
- rejectUnauthorized: typeof rejectUnauthorized === "boolean" ? rejectUnauthorized : true
584
+ rejectUnauthorized: typeof rejectUnauthorized === "boolean" ? rejectUnauthorized : true,
585
+ decompress: typeof requestOptions.decompress === "boolean" ? requestOptions.decompress : typeof defaultOptions.decompress === "boolean" ? defaultOptions.decompress : true
551
586
  };
552
587
  config.setSignal = setSignal.bind(config);
553
588
  if (requestOptions.encoding || defaultOptions.encoding) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rezo",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Lightning-fast, enterprise-grade HTTP client for modern JavaScript. Full HTTP/2 support, intelligent cookie management, multiple adapters (HTTP, Fetch, cURL, XHR), streaming, proxy support (HTTP/HTTPS/SOCKS), and cross-environment compatibility.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",