rezo 1.0.41 → 1.0.43
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/curl.cjs +143 -32
- package/dist/adapters/curl.js +143 -32
- package/dist/adapters/entries/curl.d.ts +65 -0
- package/dist/adapters/entries/fetch.d.ts +65 -0
- package/dist/adapters/entries/http.d.ts +65 -0
- package/dist/adapters/entries/http2.d.ts +65 -0
- package/dist/adapters/entries/react-native.d.ts +65 -0
- package/dist/adapters/entries/xhr.d.ts +65 -0
- package/dist/adapters/fetch.cjs +98 -12
- package/dist/adapters/fetch.js +98 -12
- package/dist/adapters/http.cjs +26 -14
- package/dist/adapters/http.js +26 -14
- package/dist/adapters/http2.cjs +756 -227
- package/dist/adapters/http2.js +756 -227
- package/dist/adapters/index.cjs +6 -6
- package/dist/adapters/xhr.cjs +94 -2
- package/dist/adapters/xhr.js +94 -2
- package/dist/cache/dns-cache.cjs +5 -3
- package/dist/cache/dns-cache.js +5 -3
- package/dist/cache/file-cacher.cjs +7 -1
- package/dist/cache/file-cacher.js +7 -1
- package/dist/cache/index.cjs +15 -13
- package/dist/cache/index.js +1 -0
- package/dist/cache/navigation-history.cjs +298 -0
- package/dist/cache/navigation-history.js +296 -0
- package/dist/cache/url-store.cjs +7 -1
- package/dist/cache/url-store.js +7 -1
- package/dist/core/rezo.cjs +7 -0
- package/dist/core/rezo.js +7 -0
- package/dist/crawler.d.ts +196 -11
- package/dist/entries/crawler.cjs +5 -5
- package/dist/index.cjs +27 -24
- package/dist/index.d.ts +73 -0
- package/dist/index.js +1 -0
- package/dist/internal/agents/base.cjs +113 -0
- package/dist/internal/agents/base.js +110 -0
- package/dist/internal/agents/http-proxy.cjs +89 -0
- package/dist/internal/agents/http-proxy.js +86 -0
- package/dist/internal/agents/https-proxy.cjs +176 -0
- package/dist/internal/agents/https-proxy.js +173 -0
- package/dist/internal/agents/index.cjs +10 -0
- package/dist/internal/agents/index.js +5 -0
- package/dist/internal/agents/socks-client.cjs +571 -0
- package/dist/internal/agents/socks-client.js +567 -0
- package/dist/internal/agents/socks-proxy.cjs +75 -0
- package/dist/internal/agents/socks-proxy.js +72 -0
- package/dist/platform/browser.d.ts +65 -0
- package/dist/platform/bun.d.ts +65 -0
- package/dist/platform/deno.d.ts +65 -0
- package/dist/platform/node.d.ts +65 -0
- package/dist/platform/react-native.d.ts +65 -0
- package/dist/platform/worker.d.ts +65 -0
- package/dist/plugin/crawler-options.cjs +1 -1
- package/dist/plugin/crawler-options.js +1 -1
- package/dist/plugin/crawler.cjs +192 -1
- package/dist/plugin/crawler.js +192 -1
- package/dist/plugin/index.cjs +36 -36
- package/dist/proxy/index.cjs +18 -16
- package/dist/proxy/index.js +17 -12
- package/dist/queue/index.cjs +8 -8
- package/dist/responses/buildError.cjs +11 -2
- package/dist/responses/buildError.js +11 -2
- package/dist/responses/universal/index.cjs +11 -11
- package/dist/utils/agent-pool.cjs +1 -17
- package/dist/utils/agent-pool.js +1 -17
- package/dist/utils/curl.cjs +317 -0
- package/dist/utils/curl.js +314 -0
- package/package.json +1 -1
package/dist/adapters/http.cjs
CHANGED
|
@@ -21,7 +21,7 @@ const { getGlobalDNSCache } = require('../cache/dns-cache.cjs');
|
|
|
21
21
|
const { ResponseCache } = require('../cache/response-cache.cjs');
|
|
22
22
|
const { getGlobalAgentPool } = require('../utils/agent-pool.cjs');
|
|
23
23
|
const { StagedTimeoutManager, parseStagedTimeouts } = require('../utils/staged-timeout.cjs');
|
|
24
|
-
const dns = require("dns");
|
|
24
|
+
const dns = require("node:dns");
|
|
25
25
|
const debugLog = {
|
|
26
26
|
requestStart: (config, url, method) => {
|
|
27
27
|
if (config.debug) {
|
|
@@ -302,7 +302,7 @@ async function executeRequest(options, defaultOptions, jar) {
|
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
try {
|
|
305
|
-
const res = executeHttp1Request(config.fetchOptions, mainConfig, config.options, perform, d_options.fs, streamResponse, downloadResponse, uploadResponse);
|
|
305
|
+
const res = executeHttp1Request(config.fetchOptions, mainConfig, config.options, perform, d_options.fs, streamResponse, downloadResponse, uploadResponse, jar);
|
|
306
306
|
if (streamResponse) {
|
|
307
307
|
res.catch((err) => {
|
|
308
308
|
streamResponse.emit("error", err);
|
|
@@ -344,7 +344,7 @@ async function executeRequest(options, defaultOptions, jar) {
|
|
|
344
344
|
throw error;
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
async function executeHttp1Request(fetchOptions, config, options, perform, fs, streamResult, downloadResult, uploadResult) {
|
|
347
|
+
async function executeHttp1Request(fetchOptions, config, options, perform, fs, streamResult, downloadResult, uploadResult, rootJar) {
|
|
348
348
|
let requestCount = 0;
|
|
349
349
|
const _stats = { statusOnNext: "abort" };
|
|
350
350
|
let responseStatusCode;
|
|
@@ -363,6 +363,9 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
363
363
|
config.setSignal();
|
|
364
364
|
const timeoutClearInstanse = config.timeoutClearInstanse;
|
|
365
365
|
delete config.timeoutClearInstanse;
|
|
366
|
+
if (!config.requestId) {
|
|
367
|
+
config.requestId = `req_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
368
|
+
}
|
|
366
369
|
const requestUrl = fetchOptions.fullUrl ? String(fetchOptions.fullUrl) : "";
|
|
367
370
|
debugLog.requestStart(config, requestUrl, fetchOptions.method || "GET");
|
|
368
371
|
const eventEmitter = streamResult || downloadResult || uploadResult;
|
|
@@ -376,7 +379,7 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
376
379
|
throw error;
|
|
377
380
|
}
|
|
378
381
|
try {
|
|
379
|
-
const response = await request(config, fetchOptions, requestCount, timing, _stats, responseStatusCode, fs, streamResult, downloadResult, uploadResult);
|
|
382
|
+
const response = await request(config, fetchOptions, requestCount, timing, _stats, responseStatusCode, fs, streamResult, downloadResult, uploadResult, rootJar);
|
|
380
383
|
const statusOnNext = _stats.statusOnNext;
|
|
381
384
|
if (response instanceof RezoError) {
|
|
382
385
|
const fileName = config.fileName;
|
|
@@ -530,8 +533,16 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
530
533
|
fetchOptions.fullUrl = location;
|
|
531
534
|
const normalizedRedirect = typeof onRedirect === "object" ? onRedirect.redirect || onRedirect.withoutBody || "body" in onRedirect : undefined;
|
|
532
535
|
if (typeof onRedirect === "object" && normalizedRedirect) {
|
|
533
|
-
|
|
536
|
+
let method;
|
|
537
|
+
const userMethod = onRedirect.method;
|
|
538
|
+
if (redirectCode === 301 || redirectCode === 302 || redirectCode === 303) {
|
|
539
|
+
method = userMethod || "GET";
|
|
540
|
+
} else {
|
|
541
|
+
method = userMethod || fetchOptions.method;
|
|
542
|
+
}
|
|
534
543
|
config.method = method;
|
|
544
|
+
options.method = method;
|
|
545
|
+
fetchOptions.method = method;
|
|
535
546
|
if (onRedirect.redirect && onRedirect.url) {
|
|
536
547
|
options.fullUrl = onRedirect.url;
|
|
537
548
|
fetchOptions.fullUrl = onRedirect.url;
|
|
@@ -580,13 +591,13 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
580
591
|
} else {
|
|
581
592
|
debugLog.redirect(config, fromUrl, fetchOptions.fullUrl, redirectCode, fetchOptions.method);
|
|
582
593
|
}
|
|
583
|
-
|
|
584
|
-
|
|
594
|
+
const jarToSync = rootJar || config.cookieJar;
|
|
595
|
+
if (response.cookies?.array?.length > 0 && jarToSync) {
|
|
585
596
|
try {
|
|
586
|
-
|
|
597
|
+
jarToSync.setCookiesSync(response.cookies.array, fromUrl);
|
|
587
598
|
} catch (e) {}
|
|
588
599
|
}
|
|
589
|
-
const __ = prepareHTTPOptions(fetchOptions,
|
|
600
|
+
const __ = prepareHTTPOptions(fetchOptions, jarToSync, addedOptions, config);
|
|
590
601
|
fetchOptions = __.fetchOptions;
|
|
591
602
|
config = __.config;
|
|
592
603
|
options = __.options;
|
|
@@ -625,7 +636,7 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
625
636
|
}
|
|
626
637
|
}
|
|
627
638
|
}
|
|
628
|
-
async function request(config, fetchOptions, requestCount, timing, _stats, responseStatusCode, fs, streamResult, downloadResult, uploadResult) {
|
|
639
|
+
async function request(config, fetchOptions, requestCount, timing, _stats, responseStatusCode, fs, streamResult, downloadResult, uploadResult, rootJar) {
|
|
629
640
|
return await new Promise(async (resolve) => {
|
|
630
641
|
try {
|
|
631
642
|
const { fullUrl, body, fileName: filename } = fetchOptions;
|
|
@@ -679,7 +690,7 @@ async function request(config, fetchOptions, requestCount, timing, _stats, respo
|
|
|
679
690
|
const location = headers["location"] || headers["Location"];
|
|
680
691
|
const contentLength = headers["content-length"];
|
|
681
692
|
const cookies = headers["set-cookie"];
|
|
682
|
-
await updateCookies(config, headers, url.href);
|
|
693
|
+
await updateCookies(config, headers, url.href, rootJar);
|
|
683
694
|
const cookieArray = config.responseCookies?.array || [];
|
|
684
695
|
delete headers["set-cookie"];
|
|
685
696
|
_stats.redirectUrl = undefined;
|
|
@@ -1618,7 +1629,7 @@ function parseProxy(proxy, isScure = true, rejectUnauthorized = false) {
|
|
|
1618
1629
|
proxyAgentCache.set(cacheKey, { agent, lastUsed: now });
|
|
1619
1630
|
return agent;
|
|
1620
1631
|
}
|
|
1621
|
-
async function updateCookies(config, headers, url) {
|
|
1632
|
+
async function updateCookies(config, headers, url, rootJar) {
|
|
1622
1633
|
const cookies = headers["set-cookie"];
|
|
1623
1634
|
if (cookies) {
|
|
1624
1635
|
const jar = new RezoCookieJar;
|
|
@@ -1657,8 +1668,9 @@ async function updateCookies(config, headers, url) {
|
|
|
1657
1668
|
acceptedCookies.push(...parsedCookies.array);
|
|
1658
1669
|
}
|
|
1659
1670
|
const acceptedCookieStrings = acceptedCookies.map((c) => c.toSetCookieString());
|
|
1660
|
-
|
|
1661
|
-
|
|
1671
|
+
const jarToUpdate = rootJar || config.cookieJar;
|
|
1672
|
+
if (!config.disableCookieJar && jarToUpdate) {
|
|
1673
|
+
jarToUpdate.setCookiesSync(acceptedCookieStrings, url);
|
|
1662
1674
|
}
|
|
1663
1675
|
jar.setCookiesSync(acceptedCookieStrings, url);
|
|
1664
1676
|
if (config.useCookies) {
|
package/dist/adapters/http.js
CHANGED
|
@@ -21,7 +21,7 @@ import { getGlobalDNSCache } from '../cache/dns-cache.js';
|
|
|
21
21
|
import { ResponseCache } from '../cache/response-cache.js';
|
|
22
22
|
import { getGlobalAgentPool } from '../utils/agent-pool.js';
|
|
23
23
|
import { StagedTimeoutManager, parseStagedTimeouts } from '../utils/staged-timeout.js';
|
|
24
|
-
import dns from "dns";
|
|
24
|
+
import dns from "node:dns";
|
|
25
25
|
const debugLog = {
|
|
26
26
|
requestStart: (config, url, method) => {
|
|
27
27
|
if (config.debug) {
|
|
@@ -302,7 +302,7 @@ export async function executeRequest(options, defaultOptions, jar) {
|
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
try {
|
|
305
|
-
const res = executeHttp1Request(config.fetchOptions, mainConfig, config.options, perform, d_options.fs, streamResponse, downloadResponse, uploadResponse);
|
|
305
|
+
const res = executeHttp1Request(config.fetchOptions, mainConfig, config.options, perform, d_options.fs, streamResponse, downloadResponse, uploadResponse, jar);
|
|
306
306
|
if (streamResponse) {
|
|
307
307
|
res.catch((err) => {
|
|
308
308
|
streamResponse.emit("error", err);
|
|
@@ -344,7 +344,7 @@ export async function executeRequest(options, defaultOptions, jar) {
|
|
|
344
344
|
throw error;
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
async function executeHttp1Request(fetchOptions, config, options, perform, fs, streamResult, downloadResult, uploadResult) {
|
|
347
|
+
async function executeHttp1Request(fetchOptions, config, options, perform, fs, streamResult, downloadResult, uploadResult, rootJar) {
|
|
348
348
|
let requestCount = 0;
|
|
349
349
|
const _stats = { statusOnNext: "abort" };
|
|
350
350
|
let responseStatusCode;
|
|
@@ -363,6 +363,9 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
363
363
|
config.setSignal();
|
|
364
364
|
const timeoutClearInstanse = config.timeoutClearInstanse;
|
|
365
365
|
delete config.timeoutClearInstanse;
|
|
366
|
+
if (!config.requestId) {
|
|
367
|
+
config.requestId = `req_${Date.now()}_${Math.random().toString(36).substring(2, 11)}`;
|
|
368
|
+
}
|
|
366
369
|
const requestUrl = fetchOptions.fullUrl ? String(fetchOptions.fullUrl) : "";
|
|
367
370
|
debugLog.requestStart(config, requestUrl, fetchOptions.method || "GET");
|
|
368
371
|
const eventEmitter = streamResult || downloadResult || uploadResult;
|
|
@@ -376,7 +379,7 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
376
379
|
throw error;
|
|
377
380
|
}
|
|
378
381
|
try {
|
|
379
|
-
const response = await request(config, fetchOptions, requestCount, timing, _stats, responseStatusCode, fs, streamResult, downloadResult, uploadResult);
|
|
382
|
+
const response = await request(config, fetchOptions, requestCount, timing, _stats, responseStatusCode, fs, streamResult, downloadResult, uploadResult, rootJar);
|
|
380
383
|
const statusOnNext = _stats.statusOnNext;
|
|
381
384
|
if (response instanceof RezoError) {
|
|
382
385
|
const fileName = config.fileName;
|
|
@@ -530,8 +533,16 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
530
533
|
fetchOptions.fullUrl = location;
|
|
531
534
|
const normalizedRedirect = typeof onRedirect === "object" ? onRedirect.redirect || onRedirect.withoutBody || "body" in onRedirect : undefined;
|
|
532
535
|
if (typeof onRedirect === "object" && normalizedRedirect) {
|
|
533
|
-
|
|
536
|
+
let method;
|
|
537
|
+
const userMethod = onRedirect.method;
|
|
538
|
+
if (redirectCode === 301 || redirectCode === 302 || redirectCode === 303) {
|
|
539
|
+
method = userMethod || "GET";
|
|
540
|
+
} else {
|
|
541
|
+
method = userMethod || fetchOptions.method;
|
|
542
|
+
}
|
|
534
543
|
config.method = method;
|
|
544
|
+
options.method = method;
|
|
545
|
+
fetchOptions.method = method;
|
|
535
546
|
if (onRedirect.redirect && onRedirect.url) {
|
|
536
547
|
options.fullUrl = onRedirect.url;
|
|
537
548
|
fetchOptions.fullUrl = onRedirect.url;
|
|
@@ -580,13 +591,13 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
580
591
|
} else {
|
|
581
592
|
debugLog.redirect(config, fromUrl, fetchOptions.fullUrl, redirectCode, fetchOptions.method);
|
|
582
593
|
}
|
|
583
|
-
|
|
584
|
-
|
|
594
|
+
const jarToSync = rootJar || config.cookieJar;
|
|
595
|
+
if (response.cookies?.array?.length > 0 && jarToSync) {
|
|
585
596
|
try {
|
|
586
|
-
|
|
597
|
+
jarToSync.setCookiesSync(response.cookies.array, fromUrl);
|
|
587
598
|
} catch (e) {}
|
|
588
599
|
}
|
|
589
|
-
const __ = prepareHTTPOptions(fetchOptions,
|
|
600
|
+
const __ = prepareHTTPOptions(fetchOptions, jarToSync, addedOptions, config);
|
|
590
601
|
fetchOptions = __.fetchOptions;
|
|
591
602
|
config = __.config;
|
|
592
603
|
options = __.options;
|
|
@@ -625,7 +636,7 @@ async function executeHttp1Request(fetchOptions, config, options, perform, fs, s
|
|
|
625
636
|
}
|
|
626
637
|
}
|
|
627
638
|
}
|
|
628
|
-
async function request(config, fetchOptions, requestCount, timing, _stats, responseStatusCode, fs, streamResult, downloadResult, uploadResult) {
|
|
639
|
+
async function request(config, fetchOptions, requestCount, timing, _stats, responseStatusCode, fs, streamResult, downloadResult, uploadResult, rootJar) {
|
|
629
640
|
return await new Promise(async (resolve) => {
|
|
630
641
|
try {
|
|
631
642
|
const { fullUrl, body, fileName: filename } = fetchOptions;
|
|
@@ -679,7 +690,7 @@ async function request(config, fetchOptions, requestCount, timing, _stats, respo
|
|
|
679
690
|
const location = headers["location"] || headers["Location"];
|
|
680
691
|
const contentLength = headers["content-length"];
|
|
681
692
|
const cookies = headers["set-cookie"];
|
|
682
|
-
await updateCookies(config, headers, url.href);
|
|
693
|
+
await updateCookies(config, headers, url.href, rootJar);
|
|
683
694
|
const cookieArray = config.responseCookies?.array || [];
|
|
684
695
|
delete headers["set-cookie"];
|
|
685
696
|
_stats.redirectUrl = undefined;
|
|
@@ -1618,7 +1629,7 @@ function parseProxy(proxy, isScure = true, rejectUnauthorized = false) {
|
|
|
1618
1629
|
proxyAgentCache.set(cacheKey, { agent, lastUsed: now });
|
|
1619
1630
|
return agent;
|
|
1620
1631
|
}
|
|
1621
|
-
async function updateCookies(config, headers, url) {
|
|
1632
|
+
async function updateCookies(config, headers, url, rootJar) {
|
|
1622
1633
|
const cookies = headers["set-cookie"];
|
|
1623
1634
|
if (cookies) {
|
|
1624
1635
|
const jar = new RezoCookieJar;
|
|
@@ -1657,8 +1668,9 @@ async function updateCookies(config, headers, url) {
|
|
|
1657
1668
|
acceptedCookies.push(...parsedCookies.array);
|
|
1658
1669
|
}
|
|
1659
1670
|
const acceptedCookieStrings = acceptedCookies.map((c) => c.toSetCookieString());
|
|
1660
|
-
|
|
1661
|
-
|
|
1671
|
+
const jarToUpdate = rootJar || config.cookieJar;
|
|
1672
|
+
if (!config.disableCookieJar && jarToUpdate) {
|
|
1673
|
+
jarToUpdate.setCookiesSync(acceptedCookieStrings, url);
|
|
1662
1674
|
}
|
|
1663
1675
|
jar.setCookiesSync(acceptedCookieStrings, url);
|
|
1664
1676
|
if (config.useCookies) {
|