rezo 1.0.10 → 1.0.12
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/dist/adapters/entries/curl.d.ts +67 -1
- package/dist/adapters/entries/fetch.d.ts +67 -1
- package/dist/adapters/entries/http.d.ts +67 -1
- package/dist/adapters/entries/http2.d.ts +67 -1
- package/dist/adapters/entries/react-native.d.ts +67 -1
- package/dist/adapters/entries/xhr.d.ts +67 -1
- package/dist/adapters/http.cjs +8 -2
- package/dist/adapters/http.js +8 -2
- package/dist/adapters/http2.cjs +4 -0
- package/dist/adapters/http2.js +4 -0
- package/dist/adapters/index.cjs +6 -6
- package/dist/cache/index.cjs +13 -13
- package/dist/core/rezo.cjs +5 -0
- package/dist/core/rezo.js +5 -0
- package/dist/crawler.d.ts +67 -1
- package/dist/entries/crawler.cjs +5 -5
- package/dist/index.cjs +24 -24
- package/dist/index.d.ts +67 -1
- package/dist/platform/browser.d.ts +67 -1
- package/dist/platform/bun.d.ts +67 -1
- package/dist/platform/deno.d.ts +67 -1
- package/dist/platform/node.d.ts +67 -1
- package/dist/platform/react-native.d.ts +67 -1
- package/dist/platform/worker.d.ts +67 -1
- package/dist/plugin/index.cjs +36 -36
- package/dist/proxy/index.cjs +2 -2
- package/dist/queue/index.cjs +8 -8
- package/dist/responses/buildResponse.cjs +28 -3
- package/dist/responses/buildResponse.js +28 -3
- package/dist/utils/http-config.cjs +8 -1
- package/dist/utils/http-config.js +8 -1
- package/package.json +1 -1
|
@@ -2502,8 +2502,73 @@ export interface RezoRequestConfig<D = any> {
|
|
|
2502
2502
|
maxRedirects?: number;
|
|
2503
2503
|
/** Whether to automatically decompress response data */
|
|
2504
2504
|
decompress?: boolean;
|
|
2505
|
-
/**
|
|
2505
|
+
/**
|
|
2506
|
+
* Whether to keep TCP connections alive for reuse across multiple requests.
|
|
2507
|
+
*
|
|
2508
|
+
* When enabled, the underlying TCP connection is kept open after a request completes,
|
|
2509
|
+
* allowing subsequent requests to the same host to reuse the connection. This reduces
|
|
2510
|
+
* latency by avoiding the overhead of establishing new connections (TCP handshake,
|
|
2511
|
+
* TLS negotiation for HTTPS).
|
|
2512
|
+
*
|
|
2513
|
+
* **Behavior:**
|
|
2514
|
+
* - `false` (default) - Connection closes after each request. Process exits immediately.
|
|
2515
|
+
* - `true` - Connection stays open for reuse. Idle connections close after `keepAliveMsecs`.
|
|
2516
|
+
*
|
|
2517
|
+
* **When to use `keepAlive: true`:**
|
|
2518
|
+
* - Making multiple requests to the same host in sequence
|
|
2519
|
+
* - Long-running applications (servers, bots, scrapers)
|
|
2520
|
+
* - Performance-critical applications where connection overhead matters
|
|
2521
|
+
*
|
|
2522
|
+
* **When to use `keepAlive: false` (default):**
|
|
2523
|
+
* - Single requests or scripts that should exit immediately
|
|
2524
|
+
* - CLI tools that make one-off requests
|
|
2525
|
+
* - When you need predictable process termination
|
|
2526
|
+
*
|
|
2527
|
+
* @example
|
|
2528
|
+
* ```typescript
|
|
2529
|
+
* // Default: process exits immediately after request
|
|
2530
|
+
* const { data } = await rezo.get('https://api.example.com/data');
|
|
2531
|
+
*
|
|
2532
|
+
* // Keep connection alive for 1 minute (default) for subsequent requests
|
|
2533
|
+
* const client = new Rezo({ keepAlive: true });
|
|
2534
|
+
* await client.get('https://api.example.com/users');
|
|
2535
|
+
* await client.get('https://api.example.com/posts'); // Reuses connection
|
|
2536
|
+
*
|
|
2537
|
+
* // Custom keep-alive timeout (30 seconds)
|
|
2538
|
+
* const client = new Rezo({ keepAlive: true, keepAliveMsecs: 30000 });
|
|
2539
|
+
* ```
|
|
2540
|
+
*
|
|
2541
|
+
* @default false
|
|
2542
|
+
*/
|
|
2506
2543
|
keepAlive?: boolean;
|
|
2544
|
+
/**
|
|
2545
|
+
* How long to keep idle connections alive in milliseconds.
|
|
2546
|
+
*
|
|
2547
|
+
* Only applies when `keepAlive: true`. After this duration of inactivity,
|
|
2548
|
+
* the connection is closed automatically. This prevents resource leaks
|
|
2549
|
+
* from connections that are no longer needed.
|
|
2550
|
+
*
|
|
2551
|
+
* **Note:** Even with keep-alive enabled, the Node.js process can still exit
|
|
2552
|
+
* cleanly when there's no other work to do, thanks to socket unreferencing.
|
|
2553
|
+
*
|
|
2554
|
+
* @example
|
|
2555
|
+
* ```typescript
|
|
2556
|
+
* // Keep connections alive for 30 seconds
|
|
2557
|
+
* const client = new Rezo({
|
|
2558
|
+
* keepAlive: true,
|
|
2559
|
+
* keepAliveMsecs: 30000
|
|
2560
|
+
* });
|
|
2561
|
+
*
|
|
2562
|
+
* // Keep connections alive for 2 minutes
|
|
2563
|
+
* const client = new Rezo({
|
|
2564
|
+
* keepAlive: true,
|
|
2565
|
+
* keepAliveMsecs: 120000
|
|
2566
|
+
* });
|
|
2567
|
+
* ```
|
|
2568
|
+
*
|
|
2569
|
+
* @default 60000 (1 minute)
|
|
2570
|
+
*/
|
|
2571
|
+
keepAliveMsecs?: number;
|
|
2507
2572
|
withoutBodyOnRedirect?: boolean;
|
|
2508
2573
|
autoSetReferer?: boolean;
|
|
2509
2574
|
autoSetOrigin?: boolean;
|
|
@@ -4104,6 +4169,7 @@ export declare class Rezo {
|
|
|
4104
4169
|
private __create;
|
|
4105
4170
|
/** Get the cookie jar for this instance */
|
|
4106
4171
|
get cookieJar(): RezoCookieJar;
|
|
4172
|
+
set cookieJar(jar: RezoCookieJar);
|
|
4107
4173
|
/**
|
|
4108
4174
|
* Save cookies to file (if cookieFile is configured).
|
|
4109
4175
|
* Can also specify a different path to save to.
|
|
@@ -2502,8 +2502,73 @@ export interface RezoRequestConfig<D = any> {
|
|
|
2502
2502
|
maxRedirects?: number;
|
|
2503
2503
|
/** Whether to automatically decompress response data */
|
|
2504
2504
|
decompress?: boolean;
|
|
2505
|
-
/**
|
|
2505
|
+
/**
|
|
2506
|
+
* Whether to keep TCP connections alive for reuse across multiple requests.
|
|
2507
|
+
*
|
|
2508
|
+
* When enabled, the underlying TCP connection is kept open after a request completes,
|
|
2509
|
+
* allowing subsequent requests to the same host to reuse the connection. This reduces
|
|
2510
|
+
* latency by avoiding the overhead of establishing new connections (TCP handshake,
|
|
2511
|
+
* TLS negotiation for HTTPS).
|
|
2512
|
+
*
|
|
2513
|
+
* **Behavior:**
|
|
2514
|
+
* - `false` (default) - Connection closes after each request. Process exits immediately.
|
|
2515
|
+
* - `true` - Connection stays open for reuse. Idle connections close after `keepAliveMsecs`.
|
|
2516
|
+
*
|
|
2517
|
+
* **When to use `keepAlive: true`:**
|
|
2518
|
+
* - Making multiple requests to the same host in sequence
|
|
2519
|
+
* - Long-running applications (servers, bots, scrapers)
|
|
2520
|
+
* - Performance-critical applications where connection overhead matters
|
|
2521
|
+
*
|
|
2522
|
+
* **When to use `keepAlive: false` (default):**
|
|
2523
|
+
* - Single requests or scripts that should exit immediately
|
|
2524
|
+
* - CLI tools that make one-off requests
|
|
2525
|
+
* - When you need predictable process termination
|
|
2526
|
+
*
|
|
2527
|
+
* @example
|
|
2528
|
+
* ```typescript
|
|
2529
|
+
* // Default: process exits immediately after request
|
|
2530
|
+
* const { data } = await rezo.get('https://api.example.com/data');
|
|
2531
|
+
*
|
|
2532
|
+
* // Keep connection alive for 1 minute (default) for subsequent requests
|
|
2533
|
+
* const client = new Rezo({ keepAlive: true });
|
|
2534
|
+
* await client.get('https://api.example.com/users');
|
|
2535
|
+
* await client.get('https://api.example.com/posts'); // Reuses connection
|
|
2536
|
+
*
|
|
2537
|
+
* // Custom keep-alive timeout (30 seconds)
|
|
2538
|
+
* const client = new Rezo({ keepAlive: true, keepAliveMsecs: 30000 });
|
|
2539
|
+
* ```
|
|
2540
|
+
*
|
|
2541
|
+
* @default false
|
|
2542
|
+
*/
|
|
2506
2543
|
keepAlive?: boolean;
|
|
2544
|
+
/**
|
|
2545
|
+
* How long to keep idle connections alive in milliseconds.
|
|
2546
|
+
*
|
|
2547
|
+
* Only applies when `keepAlive: true`. After this duration of inactivity,
|
|
2548
|
+
* the connection is closed automatically. This prevents resource leaks
|
|
2549
|
+
* from connections that are no longer needed.
|
|
2550
|
+
*
|
|
2551
|
+
* **Note:** Even with keep-alive enabled, the Node.js process can still exit
|
|
2552
|
+
* cleanly when there's no other work to do, thanks to socket unreferencing.
|
|
2553
|
+
*
|
|
2554
|
+
* @example
|
|
2555
|
+
* ```typescript
|
|
2556
|
+
* // Keep connections alive for 30 seconds
|
|
2557
|
+
* const client = new Rezo({
|
|
2558
|
+
* keepAlive: true,
|
|
2559
|
+
* keepAliveMsecs: 30000
|
|
2560
|
+
* });
|
|
2561
|
+
*
|
|
2562
|
+
* // Keep connections alive for 2 minutes
|
|
2563
|
+
* const client = new Rezo({
|
|
2564
|
+
* keepAlive: true,
|
|
2565
|
+
* keepAliveMsecs: 120000
|
|
2566
|
+
* });
|
|
2567
|
+
* ```
|
|
2568
|
+
*
|
|
2569
|
+
* @default 60000 (1 minute)
|
|
2570
|
+
*/
|
|
2571
|
+
keepAliveMsecs?: number;
|
|
2507
2572
|
withoutBodyOnRedirect?: boolean;
|
|
2508
2573
|
autoSetReferer?: boolean;
|
|
2509
2574
|
autoSetOrigin?: boolean;
|
|
@@ -4104,6 +4169,7 @@ export declare class Rezo {
|
|
|
4104
4169
|
private __create;
|
|
4105
4170
|
/** Get the cookie jar for this instance */
|
|
4106
4171
|
get cookieJar(): RezoCookieJar;
|
|
4172
|
+
set cookieJar(jar: RezoCookieJar);
|
|
4107
4173
|
/**
|
|
4108
4174
|
* Save cookies to file (if cookieFile is configured).
|
|
4109
4175
|
* Can also specify a different path to save to.
|
|
@@ -2502,8 +2502,73 @@ export interface RezoRequestConfig<D = any> {
|
|
|
2502
2502
|
maxRedirects?: number;
|
|
2503
2503
|
/** Whether to automatically decompress response data */
|
|
2504
2504
|
decompress?: boolean;
|
|
2505
|
-
/**
|
|
2505
|
+
/**
|
|
2506
|
+
* Whether to keep TCP connections alive for reuse across multiple requests.
|
|
2507
|
+
*
|
|
2508
|
+
* When enabled, the underlying TCP connection is kept open after a request completes,
|
|
2509
|
+
* allowing subsequent requests to the same host to reuse the connection. This reduces
|
|
2510
|
+
* latency by avoiding the overhead of establishing new connections (TCP handshake,
|
|
2511
|
+
* TLS negotiation for HTTPS).
|
|
2512
|
+
*
|
|
2513
|
+
* **Behavior:**
|
|
2514
|
+
* - `false` (default) - Connection closes after each request. Process exits immediately.
|
|
2515
|
+
* - `true` - Connection stays open for reuse. Idle connections close after `keepAliveMsecs`.
|
|
2516
|
+
*
|
|
2517
|
+
* **When to use `keepAlive: true`:**
|
|
2518
|
+
* - Making multiple requests to the same host in sequence
|
|
2519
|
+
* - Long-running applications (servers, bots, scrapers)
|
|
2520
|
+
* - Performance-critical applications where connection overhead matters
|
|
2521
|
+
*
|
|
2522
|
+
* **When to use `keepAlive: false` (default):**
|
|
2523
|
+
* - Single requests or scripts that should exit immediately
|
|
2524
|
+
* - CLI tools that make one-off requests
|
|
2525
|
+
* - When you need predictable process termination
|
|
2526
|
+
*
|
|
2527
|
+
* @example
|
|
2528
|
+
* ```typescript
|
|
2529
|
+
* // Default: process exits immediately after request
|
|
2530
|
+
* const { data } = await rezo.get('https://api.example.com/data');
|
|
2531
|
+
*
|
|
2532
|
+
* // Keep connection alive for 1 minute (default) for subsequent requests
|
|
2533
|
+
* const client = new Rezo({ keepAlive: true });
|
|
2534
|
+
* await client.get('https://api.example.com/users');
|
|
2535
|
+
* await client.get('https://api.example.com/posts'); // Reuses connection
|
|
2536
|
+
*
|
|
2537
|
+
* // Custom keep-alive timeout (30 seconds)
|
|
2538
|
+
* const client = new Rezo({ keepAlive: true, keepAliveMsecs: 30000 });
|
|
2539
|
+
* ```
|
|
2540
|
+
*
|
|
2541
|
+
* @default false
|
|
2542
|
+
*/
|
|
2506
2543
|
keepAlive?: boolean;
|
|
2544
|
+
/**
|
|
2545
|
+
* How long to keep idle connections alive in milliseconds.
|
|
2546
|
+
*
|
|
2547
|
+
* Only applies when `keepAlive: true`. After this duration of inactivity,
|
|
2548
|
+
* the connection is closed automatically. This prevents resource leaks
|
|
2549
|
+
* from connections that are no longer needed.
|
|
2550
|
+
*
|
|
2551
|
+
* **Note:** Even with keep-alive enabled, the Node.js process can still exit
|
|
2552
|
+
* cleanly when there's no other work to do, thanks to socket unreferencing.
|
|
2553
|
+
*
|
|
2554
|
+
* @example
|
|
2555
|
+
* ```typescript
|
|
2556
|
+
* // Keep connections alive for 30 seconds
|
|
2557
|
+
* const client = new Rezo({
|
|
2558
|
+
* keepAlive: true,
|
|
2559
|
+
* keepAliveMsecs: 30000
|
|
2560
|
+
* });
|
|
2561
|
+
*
|
|
2562
|
+
* // Keep connections alive for 2 minutes
|
|
2563
|
+
* const client = new Rezo({
|
|
2564
|
+
* keepAlive: true,
|
|
2565
|
+
* keepAliveMsecs: 120000
|
|
2566
|
+
* });
|
|
2567
|
+
* ```
|
|
2568
|
+
*
|
|
2569
|
+
* @default 60000 (1 minute)
|
|
2570
|
+
*/
|
|
2571
|
+
keepAliveMsecs?: number;
|
|
2507
2572
|
withoutBodyOnRedirect?: boolean;
|
|
2508
2573
|
autoSetReferer?: boolean;
|
|
2509
2574
|
autoSetOrigin?: boolean;
|
|
@@ -4104,6 +4169,7 @@ export declare class Rezo {
|
|
|
4104
4169
|
private __create;
|
|
4105
4170
|
/** Get the cookie jar for this instance */
|
|
4106
4171
|
get cookieJar(): RezoCookieJar;
|
|
4172
|
+
set cookieJar(jar: RezoCookieJar);
|
|
4107
4173
|
/**
|
|
4108
4174
|
* Save cookies to file (if cookieFile is configured).
|
|
4109
4175
|
* Can also specify a different path to save to.
|
|
@@ -2502,8 +2502,73 @@ export interface RezoRequestConfig<D = any> {
|
|
|
2502
2502
|
maxRedirects?: number;
|
|
2503
2503
|
/** Whether to automatically decompress response data */
|
|
2504
2504
|
decompress?: boolean;
|
|
2505
|
-
/**
|
|
2505
|
+
/**
|
|
2506
|
+
* Whether to keep TCP connections alive for reuse across multiple requests.
|
|
2507
|
+
*
|
|
2508
|
+
* When enabled, the underlying TCP connection is kept open after a request completes,
|
|
2509
|
+
* allowing subsequent requests to the same host to reuse the connection. This reduces
|
|
2510
|
+
* latency by avoiding the overhead of establishing new connections (TCP handshake,
|
|
2511
|
+
* TLS negotiation for HTTPS).
|
|
2512
|
+
*
|
|
2513
|
+
* **Behavior:**
|
|
2514
|
+
* - `false` (default) - Connection closes after each request. Process exits immediately.
|
|
2515
|
+
* - `true` - Connection stays open for reuse. Idle connections close after `keepAliveMsecs`.
|
|
2516
|
+
*
|
|
2517
|
+
* **When to use `keepAlive: true`:**
|
|
2518
|
+
* - Making multiple requests to the same host in sequence
|
|
2519
|
+
* - Long-running applications (servers, bots, scrapers)
|
|
2520
|
+
* - Performance-critical applications where connection overhead matters
|
|
2521
|
+
*
|
|
2522
|
+
* **When to use `keepAlive: false` (default):**
|
|
2523
|
+
* - Single requests or scripts that should exit immediately
|
|
2524
|
+
* - CLI tools that make one-off requests
|
|
2525
|
+
* - When you need predictable process termination
|
|
2526
|
+
*
|
|
2527
|
+
* @example
|
|
2528
|
+
* ```typescript
|
|
2529
|
+
* // Default: process exits immediately after request
|
|
2530
|
+
* const { data } = await rezo.get('https://api.example.com/data');
|
|
2531
|
+
*
|
|
2532
|
+
* // Keep connection alive for 1 minute (default) for subsequent requests
|
|
2533
|
+
* const client = new Rezo({ keepAlive: true });
|
|
2534
|
+
* await client.get('https://api.example.com/users');
|
|
2535
|
+
* await client.get('https://api.example.com/posts'); // Reuses connection
|
|
2536
|
+
*
|
|
2537
|
+
* // Custom keep-alive timeout (30 seconds)
|
|
2538
|
+
* const client = new Rezo({ keepAlive: true, keepAliveMsecs: 30000 });
|
|
2539
|
+
* ```
|
|
2540
|
+
*
|
|
2541
|
+
* @default false
|
|
2542
|
+
*/
|
|
2506
2543
|
keepAlive?: boolean;
|
|
2544
|
+
/**
|
|
2545
|
+
* How long to keep idle connections alive in milliseconds.
|
|
2546
|
+
*
|
|
2547
|
+
* Only applies when `keepAlive: true`. After this duration of inactivity,
|
|
2548
|
+
* the connection is closed automatically. This prevents resource leaks
|
|
2549
|
+
* from connections that are no longer needed.
|
|
2550
|
+
*
|
|
2551
|
+
* **Note:** Even with keep-alive enabled, the Node.js process can still exit
|
|
2552
|
+
* cleanly when there's no other work to do, thanks to socket unreferencing.
|
|
2553
|
+
*
|
|
2554
|
+
* @example
|
|
2555
|
+
* ```typescript
|
|
2556
|
+
* // Keep connections alive for 30 seconds
|
|
2557
|
+
* const client = new Rezo({
|
|
2558
|
+
* keepAlive: true,
|
|
2559
|
+
* keepAliveMsecs: 30000
|
|
2560
|
+
* });
|
|
2561
|
+
*
|
|
2562
|
+
* // Keep connections alive for 2 minutes
|
|
2563
|
+
* const client = new Rezo({
|
|
2564
|
+
* keepAlive: true,
|
|
2565
|
+
* keepAliveMsecs: 120000
|
|
2566
|
+
* });
|
|
2567
|
+
* ```
|
|
2568
|
+
*
|
|
2569
|
+
* @default 60000 (1 minute)
|
|
2570
|
+
*/
|
|
2571
|
+
keepAliveMsecs?: number;
|
|
2507
2572
|
withoutBodyOnRedirect?: boolean;
|
|
2508
2573
|
autoSetReferer?: boolean;
|
|
2509
2574
|
autoSetOrigin?: boolean;
|
|
@@ -4104,6 +4169,7 @@ export declare class Rezo {
|
|
|
4104
4169
|
private __create;
|
|
4105
4170
|
/** Get the cookie jar for this instance */
|
|
4106
4171
|
get cookieJar(): RezoCookieJar;
|
|
4172
|
+
set cookieJar(jar: RezoCookieJar);
|
|
4107
4173
|
/**
|
|
4108
4174
|
* Save cookies to file (if cookieFile is configured).
|
|
4109
4175
|
* Can also specify a different path to save to.
|
|
@@ -2502,8 +2502,73 @@ export interface RezoRequestConfig<D = any> {
|
|
|
2502
2502
|
maxRedirects?: number;
|
|
2503
2503
|
/** Whether to automatically decompress response data */
|
|
2504
2504
|
decompress?: boolean;
|
|
2505
|
-
/**
|
|
2505
|
+
/**
|
|
2506
|
+
* Whether to keep TCP connections alive for reuse across multiple requests.
|
|
2507
|
+
*
|
|
2508
|
+
* When enabled, the underlying TCP connection is kept open after a request completes,
|
|
2509
|
+
* allowing subsequent requests to the same host to reuse the connection. This reduces
|
|
2510
|
+
* latency by avoiding the overhead of establishing new connections (TCP handshake,
|
|
2511
|
+
* TLS negotiation for HTTPS).
|
|
2512
|
+
*
|
|
2513
|
+
* **Behavior:**
|
|
2514
|
+
* - `false` (default) - Connection closes after each request. Process exits immediately.
|
|
2515
|
+
* - `true` - Connection stays open for reuse. Idle connections close after `keepAliveMsecs`.
|
|
2516
|
+
*
|
|
2517
|
+
* **When to use `keepAlive: true`:**
|
|
2518
|
+
* - Making multiple requests to the same host in sequence
|
|
2519
|
+
* - Long-running applications (servers, bots, scrapers)
|
|
2520
|
+
* - Performance-critical applications where connection overhead matters
|
|
2521
|
+
*
|
|
2522
|
+
* **When to use `keepAlive: false` (default):**
|
|
2523
|
+
* - Single requests or scripts that should exit immediately
|
|
2524
|
+
* - CLI tools that make one-off requests
|
|
2525
|
+
* - When you need predictable process termination
|
|
2526
|
+
*
|
|
2527
|
+
* @example
|
|
2528
|
+
* ```typescript
|
|
2529
|
+
* // Default: process exits immediately after request
|
|
2530
|
+
* const { data } = await rezo.get('https://api.example.com/data');
|
|
2531
|
+
*
|
|
2532
|
+
* // Keep connection alive for 1 minute (default) for subsequent requests
|
|
2533
|
+
* const client = new Rezo({ keepAlive: true });
|
|
2534
|
+
* await client.get('https://api.example.com/users');
|
|
2535
|
+
* await client.get('https://api.example.com/posts'); // Reuses connection
|
|
2536
|
+
*
|
|
2537
|
+
* // Custom keep-alive timeout (30 seconds)
|
|
2538
|
+
* const client = new Rezo({ keepAlive: true, keepAliveMsecs: 30000 });
|
|
2539
|
+
* ```
|
|
2540
|
+
*
|
|
2541
|
+
* @default false
|
|
2542
|
+
*/
|
|
2506
2543
|
keepAlive?: boolean;
|
|
2544
|
+
/**
|
|
2545
|
+
* How long to keep idle connections alive in milliseconds.
|
|
2546
|
+
*
|
|
2547
|
+
* Only applies when `keepAlive: true`. After this duration of inactivity,
|
|
2548
|
+
* the connection is closed automatically. This prevents resource leaks
|
|
2549
|
+
* from connections that are no longer needed.
|
|
2550
|
+
*
|
|
2551
|
+
* **Note:** Even with keep-alive enabled, the Node.js process can still exit
|
|
2552
|
+
* cleanly when there's no other work to do, thanks to socket unreferencing.
|
|
2553
|
+
*
|
|
2554
|
+
* @example
|
|
2555
|
+
* ```typescript
|
|
2556
|
+
* // Keep connections alive for 30 seconds
|
|
2557
|
+
* const client = new Rezo({
|
|
2558
|
+
* keepAlive: true,
|
|
2559
|
+
* keepAliveMsecs: 30000
|
|
2560
|
+
* });
|
|
2561
|
+
*
|
|
2562
|
+
* // Keep connections alive for 2 minutes
|
|
2563
|
+
* const client = new Rezo({
|
|
2564
|
+
* keepAlive: true,
|
|
2565
|
+
* keepAliveMsecs: 120000
|
|
2566
|
+
* });
|
|
2567
|
+
* ```
|
|
2568
|
+
*
|
|
2569
|
+
* @default 60000 (1 minute)
|
|
2570
|
+
*/
|
|
2571
|
+
keepAliveMsecs?: number;
|
|
2507
2572
|
withoutBodyOnRedirect?: boolean;
|
|
2508
2573
|
autoSetReferer?: boolean;
|
|
2509
2574
|
autoSetOrigin?: boolean;
|
|
@@ -4104,6 +4169,7 @@ export declare class Rezo {
|
|
|
4104
4169
|
private __create;
|
|
4105
4170
|
/** Get the cookie jar for this instance */
|
|
4106
4171
|
get cookieJar(): RezoCookieJar;
|
|
4172
|
+
set cookieJar(jar: RezoCookieJar);
|
|
4107
4173
|
/**
|
|
4108
4174
|
* Save cookies to file (if cookieFile is configured).
|
|
4109
4175
|
* Can also specify a different path to save to.
|
|
@@ -2502,8 +2502,73 @@ export interface RezoRequestConfig<D = any> {
|
|
|
2502
2502
|
maxRedirects?: number;
|
|
2503
2503
|
/** Whether to automatically decompress response data */
|
|
2504
2504
|
decompress?: boolean;
|
|
2505
|
-
/**
|
|
2505
|
+
/**
|
|
2506
|
+
* Whether to keep TCP connections alive for reuse across multiple requests.
|
|
2507
|
+
*
|
|
2508
|
+
* When enabled, the underlying TCP connection is kept open after a request completes,
|
|
2509
|
+
* allowing subsequent requests to the same host to reuse the connection. This reduces
|
|
2510
|
+
* latency by avoiding the overhead of establishing new connections (TCP handshake,
|
|
2511
|
+
* TLS negotiation for HTTPS).
|
|
2512
|
+
*
|
|
2513
|
+
* **Behavior:**
|
|
2514
|
+
* - `false` (default) - Connection closes after each request. Process exits immediately.
|
|
2515
|
+
* - `true` - Connection stays open for reuse. Idle connections close after `keepAliveMsecs`.
|
|
2516
|
+
*
|
|
2517
|
+
* **When to use `keepAlive: true`:**
|
|
2518
|
+
* - Making multiple requests to the same host in sequence
|
|
2519
|
+
* - Long-running applications (servers, bots, scrapers)
|
|
2520
|
+
* - Performance-critical applications where connection overhead matters
|
|
2521
|
+
*
|
|
2522
|
+
* **When to use `keepAlive: false` (default):**
|
|
2523
|
+
* - Single requests or scripts that should exit immediately
|
|
2524
|
+
* - CLI tools that make one-off requests
|
|
2525
|
+
* - When you need predictable process termination
|
|
2526
|
+
*
|
|
2527
|
+
* @example
|
|
2528
|
+
* ```typescript
|
|
2529
|
+
* // Default: process exits immediately after request
|
|
2530
|
+
* const { data } = await rezo.get('https://api.example.com/data');
|
|
2531
|
+
*
|
|
2532
|
+
* // Keep connection alive for 1 minute (default) for subsequent requests
|
|
2533
|
+
* const client = new Rezo({ keepAlive: true });
|
|
2534
|
+
* await client.get('https://api.example.com/users');
|
|
2535
|
+
* await client.get('https://api.example.com/posts'); // Reuses connection
|
|
2536
|
+
*
|
|
2537
|
+
* // Custom keep-alive timeout (30 seconds)
|
|
2538
|
+
* const client = new Rezo({ keepAlive: true, keepAliveMsecs: 30000 });
|
|
2539
|
+
* ```
|
|
2540
|
+
*
|
|
2541
|
+
* @default false
|
|
2542
|
+
*/
|
|
2506
2543
|
keepAlive?: boolean;
|
|
2544
|
+
/**
|
|
2545
|
+
* How long to keep idle connections alive in milliseconds.
|
|
2546
|
+
*
|
|
2547
|
+
* Only applies when `keepAlive: true`. After this duration of inactivity,
|
|
2548
|
+
* the connection is closed automatically. This prevents resource leaks
|
|
2549
|
+
* from connections that are no longer needed.
|
|
2550
|
+
*
|
|
2551
|
+
* **Note:** Even with keep-alive enabled, the Node.js process can still exit
|
|
2552
|
+
* cleanly when there's no other work to do, thanks to socket unreferencing.
|
|
2553
|
+
*
|
|
2554
|
+
* @example
|
|
2555
|
+
* ```typescript
|
|
2556
|
+
* // Keep connections alive for 30 seconds
|
|
2557
|
+
* const client = new Rezo({
|
|
2558
|
+
* keepAlive: true,
|
|
2559
|
+
* keepAliveMsecs: 30000
|
|
2560
|
+
* });
|
|
2561
|
+
*
|
|
2562
|
+
* // Keep connections alive for 2 minutes
|
|
2563
|
+
* const client = new Rezo({
|
|
2564
|
+
* keepAlive: true,
|
|
2565
|
+
* keepAliveMsecs: 120000
|
|
2566
|
+
* });
|
|
2567
|
+
* ```
|
|
2568
|
+
*
|
|
2569
|
+
* @default 60000 (1 minute)
|
|
2570
|
+
*/
|
|
2571
|
+
keepAliveMsecs?: number;
|
|
2507
2572
|
withoutBodyOnRedirect?: boolean;
|
|
2508
2573
|
autoSetReferer?: boolean;
|
|
2509
2574
|
autoSetOrigin?: boolean;
|
|
@@ -4104,6 +4169,7 @@ export declare class Rezo {
|
|
|
4104
4169
|
private __create;
|
|
4105
4170
|
/** Get the cookie jar for this instance */
|
|
4106
4171
|
get cookieJar(): RezoCookieJar;
|
|
4172
|
+
set cookieJar(jar: RezoCookieJar);
|
|
4107
4173
|
/**
|
|
4108
4174
|
* Save cookies to file (if cookieFile is configured).
|
|
4109
4175
|
* Can also specify a different path to save to.
|
package/dist/adapters/http.cjs
CHANGED
|
@@ -767,6 +767,9 @@ async function request(config, fetchOptions, requestCount, timing, _stats, respo
|
|
|
767
767
|
}
|
|
768
768
|
});
|
|
769
769
|
req.on("socket", (socket) => {
|
|
770
|
+
if (socket && typeof socket.unref === "function") {
|
|
771
|
+
socket.unref();
|
|
772
|
+
}
|
|
770
773
|
timing.dnsStart = performance.now();
|
|
771
774
|
socket.on("lookup", () => {
|
|
772
775
|
if (!config.timing.dnsMs) {
|
|
@@ -944,13 +947,16 @@ function buildHTTPOptions(fetchOptions, isSecure, url) {
|
|
|
944
947
|
rejectUnauthorized,
|
|
945
948
|
useSecureContext = true,
|
|
946
949
|
auth,
|
|
947
|
-
dnsCache: dnsCacheOption
|
|
950
|
+
dnsCache: dnsCacheOption,
|
|
951
|
+
keepAlive = false,
|
|
952
|
+
keepAliveMsecs = 60000
|
|
948
953
|
} = fetchOptions;
|
|
949
954
|
const secureContext = isSecure && useSecureContext ? new https.Agent({
|
|
950
955
|
secureContext: createSecureContext(),
|
|
951
956
|
servername: url.host,
|
|
952
957
|
rejectUnauthorized,
|
|
953
|
-
keepAlive
|
|
958
|
+
keepAlive,
|
|
959
|
+
keepAliveMsecs: keepAlive ? keepAliveMsecs : undefined
|
|
954
960
|
}) : undefined;
|
|
955
961
|
const customAgent = url.protocol === "https:" && httpsAgent ? httpsAgent : httpAgent ? httpAgent : undefined;
|
|
956
962
|
const agent = parseProxy(proxy) || customAgent || secureContext;
|
package/dist/adapters/http.js
CHANGED
|
@@ -767,6 +767,9 @@ async function request(config, fetchOptions, requestCount, timing, _stats, respo
|
|
|
767
767
|
}
|
|
768
768
|
});
|
|
769
769
|
req.on("socket", (socket) => {
|
|
770
|
+
if (socket && typeof socket.unref === "function") {
|
|
771
|
+
socket.unref();
|
|
772
|
+
}
|
|
770
773
|
timing.dnsStart = performance.now();
|
|
771
774
|
socket.on("lookup", () => {
|
|
772
775
|
if (!config.timing.dnsMs) {
|
|
@@ -944,13 +947,16 @@ function buildHTTPOptions(fetchOptions, isSecure, url) {
|
|
|
944
947
|
rejectUnauthorized,
|
|
945
948
|
useSecureContext = true,
|
|
946
949
|
auth,
|
|
947
|
-
dnsCache: dnsCacheOption
|
|
950
|
+
dnsCache: dnsCacheOption,
|
|
951
|
+
keepAlive = false,
|
|
952
|
+
keepAliveMsecs = 60000
|
|
948
953
|
} = fetchOptions;
|
|
949
954
|
const secureContext = isSecure && useSecureContext ? new https.Agent({
|
|
950
955
|
secureContext: createSecureContext(),
|
|
951
956
|
servername: url.host,
|
|
952
957
|
rejectUnauthorized,
|
|
953
|
-
keepAlive
|
|
958
|
+
keepAlive,
|
|
959
|
+
keepAliveMsecs: keepAlive ? keepAliveMsecs : undefined
|
|
954
960
|
}) : undefined;
|
|
955
961
|
const customAgent = url.protocol === "https:" && httpsAgent ? httpsAgent : httpAgent ? httpAgent : undefined;
|
|
956
962
|
const agent = parseProxy(proxy) || customAgent || secureContext;
|
package/dist/adapters/http2.cjs
CHANGED
package/dist/adapters/http2.js
CHANGED
package/dist/adapters/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const
|
|
2
|
-
exports.detectRuntime =
|
|
3
|
-
exports.getAdapterCapabilities =
|
|
4
|
-
exports.buildAdapterContext =
|
|
5
|
-
exports.getAvailableAdapters =
|
|
6
|
-
exports.selectAdapter =
|
|
1
|
+
const _mod_879ve5 = require('./picker.cjs');
|
|
2
|
+
exports.detectRuntime = _mod_879ve5.detectRuntime;
|
|
3
|
+
exports.getAdapterCapabilities = _mod_879ve5.getAdapterCapabilities;
|
|
4
|
+
exports.buildAdapterContext = _mod_879ve5.buildAdapterContext;
|
|
5
|
+
exports.getAvailableAdapters = _mod_879ve5.getAvailableAdapters;
|
|
6
|
+
exports.selectAdapter = _mod_879ve5.selectAdapter;;
|
package/dist/cache/index.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const
|
|
2
|
-
exports.LRUCache =
|
|
3
|
-
const
|
|
4
|
-
exports.DNSCache =
|
|
5
|
-
exports.getGlobalDNSCache =
|
|
6
|
-
exports.resetGlobalDNSCache =
|
|
7
|
-
const
|
|
8
|
-
exports.ResponseCache =
|
|
9
|
-
exports.normalizeResponseCacheConfig =
|
|
10
|
-
const
|
|
11
|
-
exports.FileCacher =
|
|
12
|
-
const
|
|
13
|
-
exports.UrlStore =
|
|
1
|
+
const _mod_2rlcbw = require('./lru-cache.cjs');
|
|
2
|
+
exports.LRUCache = _mod_2rlcbw.LRUCache;;
|
|
3
|
+
const _mod_faep7r = require('./dns-cache.cjs');
|
|
4
|
+
exports.DNSCache = _mod_faep7r.DNSCache;
|
|
5
|
+
exports.getGlobalDNSCache = _mod_faep7r.getGlobalDNSCache;
|
|
6
|
+
exports.resetGlobalDNSCache = _mod_faep7r.resetGlobalDNSCache;;
|
|
7
|
+
const _mod_kp3skc = require('./response-cache.cjs');
|
|
8
|
+
exports.ResponseCache = _mod_kp3skc.ResponseCache;
|
|
9
|
+
exports.normalizeResponseCacheConfig = _mod_kp3skc.normalizeResponseCacheConfig;;
|
|
10
|
+
const _mod_dok148 = require('./file-cacher.cjs');
|
|
11
|
+
exports.FileCacher = _mod_dok148.FileCacher;;
|
|
12
|
+
const _mod_wzzzfr = require('./url-store.cjs');
|
|
13
|
+
exports.UrlStore = _mod_wzzzfr.UrlStore;;
|
package/dist/core/rezo.cjs
CHANGED
|
@@ -361,6 +361,9 @@ class Rezo {
|
|
|
361
361
|
get cookieJar() {
|
|
362
362
|
return this.jar;
|
|
363
363
|
}
|
|
364
|
+
set cookieJar(jar) {
|
|
365
|
+
this.jar = jar;
|
|
366
|
+
}
|
|
364
367
|
saveCookies(filePath) {
|
|
365
368
|
if (filePath) {
|
|
366
369
|
this.jar.saveToFile(filePath);
|
|
@@ -397,6 +400,8 @@ class Rezo {
|
|
|
397
400
|
}, this.defaults, this.jar);
|
|
398
401
|
}
|
|
399
402
|
setCookies(cookies, url, startNew) {
|
|
403
|
+
if (!this.jar)
|
|
404
|
+
this.jar = new RezoCookieJar;
|
|
400
405
|
if (startNew)
|
|
401
406
|
this.jar.removeAllCookiesSync();
|
|
402
407
|
this.jar.setCookiesSync(cookies, url);
|
package/dist/core/rezo.js
CHANGED
|
@@ -361,6 +361,9 @@ export class Rezo {
|
|
|
361
361
|
get cookieJar() {
|
|
362
362
|
return this.jar;
|
|
363
363
|
}
|
|
364
|
+
set cookieJar(jar) {
|
|
365
|
+
this.jar = jar;
|
|
366
|
+
}
|
|
364
367
|
saveCookies(filePath) {
|
|
365
368
|
if (filePath) {
|
|
366
369
|
this.jar.saveToFile(filePath);
|
|
@@ -397,6 +400,8 @@ export class Rezo {
|
|
|
397
400
|
}, this.defaults, this.jar);
|
|
398
401
|
}
|
|
399
402
|
setCookies(cookies, url, startNew) {
|
|
403
|
+
if (!this.jar)
|
|
404
|
+
this.jar = new RezoCookieJar;
|
|
400
405
|
if (startNew)
|
|
401
406
|
this.jar.removeAllCookiesSync();
|
|
402
407
|
this.jar.setCookiesSync(cookies, url);
|