rezo 1.0.2 → 1.0.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 +261 -0
- package/dist/adapters/curl.cjs +47 -1
- package/dist/adapters/curl.js +47 -1
- package/dist/adapters/entries/curl.cjs +31 -4
- package/dist/adapters/entries/curl.d.ts +2576 -847
- package/dist/adapters/entries/curl.js +29 -2
- package/dist/adapters/entries/fetch.cjs +31 -2
- package/dist/adapters/entries/fetch.d.ts +1753 -15
- package/dist/adapters/entries/fetch.js +29 -1
- package/dist/adapters/entries/http.cjs +31 -2
- package/dist/adapters/entries/http.d.ts +1774 -14
- package/dist/adapters/entries/http.js +29 -1
- package/dist/adapters/entries/http2.cjs +31 -4
- package/dist/adapters/entries/http2.d.ts +1748 -19
- package/dist/adapters/entries/http2.js +29 -2
- package/dist/adapters/entries/react-native.cjs +31 -2
- package/dist/adapters/entries/react-native.d.ts +1753 -14
- package/dist/adapters/entries/react-native.js +29 -1
- package/dist/adapters/entries/xhr.cjs +31 -2
- package/dist/adapters/entries/xhr.d.ts +1753 -15
- package/dist/adapters/entries/xhr.js +29 -1
- package/dist/adapters/fetch.cjs +24 -20
- package/dist/adapters/fetch.js +24 -20
- package/dist/adapters/http.cjs +69 -19
- package/dist/adapters/http.js +69 -19
- package/dist/adapters/http2.cjs +69 -19
- package/dist/adapters/http2.js +69 -19
- package/dist/adapters/index.cjs +6 -6
- package/dist/cache/index.cjs +13 -13
- package/dist/core/hooks.cjs +16 -0
- package/dist/core/hooks.js +16 -0
- package/dist/core/rezo.cjs +23 -1
- package/dist/core/rezo.js +23 -1
- package/dist/crawler.d.ts +528 -5
- package/dist/entries/crawler.cjs +5 -5
- package/dist/index.cjs +18 -16
- package/dist/index.d.ts +564 -5
- package/dist/index.js +1 -0
- package/dist/platform/browser.cjs +24 -2
- package/dist/platform/browser.d.ts +672 -10
- package/dist/platform/browser.js +24 -2
- package/dist/platform/bun.cjs +24 -2
- package/dist/platform/bun.d.ts +672 -10
- package/dist/platform/bun.js +24 -2
- package/dist/platform/deno.cjs +24 -2
- package/dist/platform/deno.d.ts +672 -10
- package/dist/platform/deno.js +24 -2
- package/dist/platform/node.cjs +24 -2
- package/dist/platform/node.d.ts +672 -10
- package/dist/platform/node.js +24 -2
- package/dist/platform/react-native.cjs +24 -2
- package/dist/platform/react-native.d.ts +672 -10
- package/dist/platform/react-native.js +24 -2
- package/dist/platform/worker.cjs +24 -2
- package/dist/platform/worker.d.ts +672 -10
- package/dist/platform/worker.js +24 -2
- package/dist/plugin/index.cjs +36 -36
- package/dist/proxy/index.cjs +2 -0
- package/dist/proxy/index.js +1 -0
- package/dist/proxy/manager.cjs +446 -0
- package/dist/proxy/manager.js +444 -0
- package/dist/utils/http-config.cjs +14 -3
- package/dist/utils/http-config.js +14 -3
- package/package.json +19 -4
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import { executeRequest } from '../xhr.js';
|
|
2
|
+
import { setGlobalAdapter, createRezoInstance, Rezo } from '../../core/rezo.js';
|
|
3
|
+
import { RezoError, RezoErrorCode } from '../../errors/rezo-error.js';
|
|
4
|
+
import { RezoHeaders } from '../../utils/headers.js';
|
|
5
|
+
import { RezoFormData } from '../../utils/form-data.js';
|
|
6
|
+
import { RezoCookieJar } from '../../utils/cookies.js';
|
|
7
|
+
import { createDefaultHooks, mergeHooks } from '../../core/hooks.js';
|
|
8
|
+
import packageJson from "../../../package.json" with { type: 'json' };
|
|
9
|
+
|
|
10
|
+
export { Rezo };
|
|
11
|
+
export { RezoError };
|
|
12
|
+
export { RezoErrorCode };
|
|
13
|
+
export { RezoHeaders };
|
|
14
|
+
export { RezoFormData };
|
|
15
|
+
export { RezoCookieJar };
|
|
16
|
+
export { createDefaultHooks };
|
|
17
|
+
export { mergeHooks };
|
|
18
|
+
export const isRezoError = RezoError.isRezoError;
|
|
19
|
+
export const Cancel = RezoError;
|
|
20
|
+
export const CancelToken = AbortController;
|
|
21
|
+
export const isCancel = (error) => {
|
|
22
|
+
return error instanceof RezoError && error.code === "ECONNABORTED";
|
|
23
|
+
};
|
|
24
|
+
export const all = Promise.all.bind(Promise);
|
|
25
|
+
export const spread = (callback) => (array) => callback(...array);
|
|
26
|
+
export const VERSION = packageJson.version;
|
|
27
|
+
setGlobalAdapter(executeRequest);
|
|
28
|
+
const rezo = createRezoInstance(executeRequest);
|
|
29
|
+
export default rezo;
|
package/dist/adapters/fetch.cjs
CHANGED
|
@@ -248,29 +248,33 @@ async function executeRequest(options, defaultOptions, jar) {
|
|
|
248
248
|
const url = typeof fetchOptions.url === "string" ? fetchOptions.url : fetchOptions.url?.toString() || "";
|
|
249
249
|
uploadResponse = new UploadResponse(url);
|
|
250
250
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const response = await res;
|
|
260
|
-
if (cache && !isStream && !isDownload && !isUpload) {
|
|
261
|
-
if (response.status === 304 && cachedEntry) {
|
|
262
|
-
const responseHeaders = response.headers instanceof RezoHeaders ? Object.fromEntries(response.headers.entries()) : response.headers;
|
|
263
|
-
const updatedCached = cache.updateRevalidated(method, requestUrl, responseHeaders, requestHeaders);
|
|
264
|
-
if (updatedCached) {
|
|
265
|
-
return buildCachedRezoResponse(updatedCached, mainConfig);
|
|
266
|
-
}
|
|
267
|
-
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
251
|
+
try {
|
|
252
|
+
const res = executeFetchRequest(fetchOptions, mainConfig, options, perform, streamResponse, downloadResponse, uploadResponse);
|
|
253
|
+
if (streamResponse) {
|
|
254
|
+
return streamResponse;
|
|
255
|
+
} else if (downloadResponse) {
|
|
256
|
+
return downloadResponse;
|
|
257
|
+
} else if (uploadResponse) {
|
|
258
|
+
return uploadResponse;
|
|
268
259
|
}
|
|
269
|
-
|
|
270
|
-
|
|
260
|
+
const response = await res;
|
|
261
|
+
if (cache && !isStream && !isDownload && !isUpload) {
|
|
262
|
+
if (response.status === 304 && cachedEntry) {
|
|
263
|
+
const responseHeaders = response.headers instanceof RezoHeaders ? Object.fromEntries(response.headers.entries()) : response.headers;
|
|
264
|
+
const updatedCached = cache.updateRevalidated(method, requestUrl, responseHeaders, requestHeaders);
|
|
265
|
+
if (updatedCached) {
|
|
266
|
+
return buildCachedRezoResponse(updatedCached, mainConfig);
|
|
267
|
+
}
|
|
268
|
+
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
269
|
+
}
|
|
270
|
+
if (response.status >= 200 && response.status < 300) {
|
|
271
|
+
cache.set(method, requestUrl, response, requestHeaders);
|
|
272
|
+
}
|
|
271
273
|
}
|
|
274
|
+
return response;
|
|
275
|
+
} catch (error) {
|
|
276
|
+
throw error;
|
|
272
277
|
}
|
|
273
|
-
return response;
|
|
274
278
|
}
|
|
275
279
|
async function executeFetchRequest(fetchOptions, config, options, perform, streamResult, downloadResult, uploadResult) {
|
|
276
280
|
let requestCount = 0;
|
package/dist/adapters/fetch.js
CHANGED
|
@@ -248,29 +248,33 @@ export async function executeRequest(options, defaultOptions, jar) {
|
|
|
248
248
|
const url = typeof fetchOptions.url === "string" ? fetchOptions.url : fetchOptions.url?.toString() || "";
|
|
249
249
|
uploadResponse = new UploadResponse(url);
|
|
250
250
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const response = await res;
|
|
260
|
-
if (cache && !isStream && !isDownload && !isUpload) {
|
|
261
|
-
if (response.status === 304 && cachedEntry) {
|
|
262
|
-
const responseHeaders = response.headers instanceof RezoHeaders ? Object.fromEntries(response.headers.entries()) : response.headers;
|
|
263
|
-
const updatedCached = cache.updateRevalidated(method, requestUrl, responseHeaders, requestHeaders);
|
|
264
|
-
if (updatedCached) {
|
|
265
|
-
return buildCachedRezoResponse(updatedCached, mainConfig);
|
|
266
|
-
}
|
|
267
|
-
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
251
|
+
try {
|
|
252
|
+
const res = executeFetchRequest(fetchOptions, mainConfig, options, perform, streamResponse, downloadResponse, uploadResponse);
|
|
253
|
+
if (streamResponse) {
|
|
254
|
+
return streamResponse;
|
|
255
|
+
} else if (downloadResponse) {
|
|
256
|
+
return downloadResponse;
|
|
257
|
+
} else if (uploadResponse) {
|
|
258
|
+
return uploadResponse;
|
|
268
259
|
}
|
|
269
|
-
|
|
270
|
-
|
|
260
|
+
const response = await res;
|
|
261
|
+
if (cache && !isStream && !isDownload && !isUpload) {
|
|
262
|
+
if (response.status === 304 && cachedEntry) {
|
|
263
|
+
const responseHeaders = response.headers instanceof RezoHeaders ? Object.fromEntries(response.headers.entries()) : response.headers;
|
|
264
|
+
const updatedCached = cache.updateRevalidated(method, requestUrl, responseHeaders, requestHeaders);
|
|
265
|
+
if (updatedCached) {
|
|
266
|
+
return buildCachedRezoResponse(updatedCached, mainConfig);
|
|
267
|
+
}
|
|
268
|
+
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
269
|
+
}
|
|
270
|
+
if (response.status >= 200 && response.status < 300) {
|
|
271
|
+
cache.set(method, requestUrl, response, requestHeaders);
|
|
272
|
+
}
|
|
271
273
|
}
|
|
274
|
+
return response;
|
|
275
|
+
} catch (error) {
|
|
276
|
+
throw error;
|
|
272
277
|
}
|
|
273
|
-
return response;
|
|
274
278
|
}
|
|
275
279
|
async function executeFetchRequest(fetchOptions, config, options, perform, streamResult, downloadResult, uploadResult) {
|
|
276
280
|
let requestCount = 0;
|
package/dist/adapters/http.cjs
CHANGED
|
@@ -96,10 +96,26 @@ async function executeRequest(options, defaultOptions, jar) {
|
|
|
96
96
|
if (!options.responseType) {
|
|
97
97
|
options.responseType = "auto";
|
|
98
98
|
}
|
|
99
|
-
const d_options = await getDefaultConfig(defaultOptions);
|
|
99
|
+
const d_options = await getDefaultConfig(defaultOptions, defaultOptions._proxyManager);
|
|
100
100
|
const config = prepareHTTPOptions(options, jar, { defaultOptions: d_options });
|
|
101
101
|
let mainConfig = config.config;
|
|
102
|
+
const { proxyManager } = config;
|
|
102
103
|
const perform = new RezoPerformance;
|
|
104
|
+
let selectedProxy = null;
|
|
105
|
+
if (proxyManager) {
|
|
106
|
+
const requestUrl = typeof config.fetchOptions.url === "string" ? config.fetchOptions.url : config.fetchOptions.url?.toString() || "";
|
|
107
|
+
selectedProxy = proxyManager.next(requestUrl);
|
|
108
|
+
if (selectedProxy) {
|
|
109
|
+
config.fetchOptions.proxy = {
|
|
110
|
+
protocol: selectedProxy.protocol,
|
|
111
|
+
host: selectedProxy.host,
|
|
112
|
+
port: selectedProxy.port,
|
|
113
|
+
auth: selectedProxy.auth
|
|
114
|
+
};
|
|
115
|
+
} else if (proxyManager.config.failWithoutProxy) {
|
|
116
|
+
throw new RezoError("No proxy available: All proxies exhausted or URL did not match whitelist/blacklist", mainConfig, "UNQ_NO_PROXY_AVAILABLE", config.fetchOptions);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
103
119
|
const cacheOption = options.cache;
|
|
104
120
|
const method = (options.method || "GET").toUpperCase();
|
|
105
121
|
const requestUrl = typeof config.fetchOptions.url === "string" ? config.fetchOptions.url : config.fetchOptions.url?.toString() || "";
|
|
@@ -153,29 +169,63 @@ async function executeRequest(options, defaultOptions, jar) {
|
|
|
153
169
|
const url = typeof config.fetchOptions.url === "string" ? config.fetchOptions.url : config.fetchOptions.url.toString();
|
|
154
170
|
uploadResponse = new UploadResponse(url, fileName);
|
|
155
171
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
172
|
+
if (proxyManager && selectedProxy) {
|
|
173
|
+
if (streamResponse) {
|
|
174
|
+
streamResponse.on("finish", () => {
|
|
175
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
176
|
+
});
|
|
177
|
+
streamResponse.on("error", (err) => {
|
|
178
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
179
|
+
});
|
|
180
|
+
} else if (downloadResponse) {
|
|
181
|
+
downloadResponse.on("finish", () => {
|
|
182
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
183
|
+
});
|
|
184
|
+
downloadResponse.on("error", (err) => {
|
|
185
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
186
|
+
});
|
|
187
|
+
} else if (uploadResponse) {
|
|
188
|
+
uploadResponse.on("finish", () => {
|
|
189
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
190
|
+
});
|
|
191
|
+
uploadResponse.on("error", (err) => {
|
|
192
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
163
195
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
196
|
+
try {
|
|
197
|
+
const res = executeHttp1Request(config.fetchOptions, mainConfig, config.options, perform, d_options.fs, streamResponse, downloadResponse, uploadResponse);
|
|
198
|
+
if (streamResponse) {
|
|
199
|
+
return streamResponse;
|
|
200
|
+
} else if (downloadResponse) {
|
|
201
|
+
return downloadResponse;
|
|
202
|
+
} else if (uploadResponse) {
|
|
203
|
+
return uploadResponse;
|
|
204
|
+
}
|
|
205
|
+
const response = await res;
|
|
206
|
+
if (proxyManager && selectedProxy) {
|
|
207
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
208
|
+
}
|
|
209
|
+
if (cache && !isStream && !isDownload && !isUpload) {
|
|
210
|
+
if (response.status === 304 && cachedEntry) {
|
|
211
|
+
const responseHeaders = response.headers instanceof RezoHeaders ? Object.fromEntries(response.headers.entries()) : response.headers;
|
|
212
|
+
const updatedCached = cache.updateRevalidated(method, requestUrl, responseHeaders, requestHeaders);
|
|
213
|
+
if (updatedCached) {
|
|
214
|
+
return buildCachedRezoResponse(updatedCached, mainConfig);
|
|
215
|
+
}
|
|
216
|
+
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
217
|
+
}
|
|
218
|
+
if (response.status >= 200 && response.status < 300) {
|
|
219
|
+
cache.set(method, requestUrl, response, requestHeaders);
|
|
171
220
|
}
|
|
172
|
-
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
173
221
|
}
|
|
174
|
-
|
|
175
|
-
|
|
222
|
+
return response;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (proxyManager && selectedProxy) {
|
|
225
|
+
proxyManager.reportFailure(selectedProxy, error);
|
|
176
226
|
}
|
|
227
|
+
throw error;
|
|
177
228
|
}
|
|
178
|
-
return response;
|
|
179
229
|
}
|
|
180
230
|
async function executeHttp1Request(fetchOptions, config, options, perform, fs, streamResult, downloadResult, uploadResult) {
|
|
181
231
|
let requestCount = 0;
|
package/dist/adapters/http.js
CHANGED
|
@@ -96,10 +96,26 @@ export async function executeRequest(options, defaultOptions, jar) {
|
|
|
96
96
|
if (!options.responseType) {
|
|
97
97
|
options.responseType = "auto";
|
|
98
98
|
}
|
|
99
|
-
const d_options = await getDefaultConfig(defaultOptions);
|
|
99
|
+
const d_options = await getDefaultConfig(defaultOptions, defaultOptions._proxyManager);
|
|
100
100
|
const config = prepareHTTPOptions(options, jar, { defaultOptions: d_options });
|
|
101
101
|
let mainConfig = config.config;
|
|
102
|
+
const { proxyManager } = config;
|
|
102
103
|
const perform = new RezoPerformance;
|
|
104
|
+
let selectedProxy = null;
|
|
105
|
+
if (proxyManager) {
|
|
106
|
+
const requestUrl = typeof config.fetchOptions.url === "string" ? config.fetchOptions.url : config.fetchOptions.url?.toString() || "";
|
|
107
|
+
selectedProxy = proxyManager.next(requestUrl);
|
|
108
|
+
if (selectedProxy) {
|
|
109
|
+
config.fetchOptions.proxy = {
|
|
110
|
+
protocol: selectedProxy.protocol,
|
|
111
|
+
host: selectedProxy.host,
|
|
112
|
+
port: selectedProxy.port,
|
|
113
|
+
auth: selectedProxy.auth
|
|
114
|
+
};
|
|
115
|
+
} else if (proxyManager.config.failWithoutProxy) {
|
|
116
|
+
throw new RezoError("No proxy available: All proxies exhausted or URL did not match whitelist/blacklist", mainConfig, "UNQ_NO_PROXY_AVAILABLE", config.fetchOptions);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
103
119
|
const cacheOption = options.cache;
|
|
104
120
|
const method = (options.method || "GET").toUpperCase();
|
|
105
121
|
const requestUrl = typeof config.fetchOptions.url === "string" ? config.fetchOptions.url : config.fetchOptions.url?.toString() || "";
|
|
@@ -153,29 +169,63 @@ export async function executeRequest(options, defaultOptions, jar) {
|
|
|
153
169
|
const url = typeof config.fetchOptions.url === "string" ? config.fetchOptions.url : config.fetchOptions.url.toString();
|
|
154
170
|
uploadResponse = new UploadResponse(url, fileName);
|
|
155
171
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
172
|
+
if (proxyManager && selectedProxy) {
|
|
173
|
+
if (streamResponse) {
|
|
174
|
+
streamResponse.on("finish", () => {
|
|
175
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
176
|
+
});
|
|
177
|
+
streamResponse.on("error", (err) => {
|
|
178
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
179
|
+
});
|
|
180
|
+
} else if (downloadResponse) {
|
|
181
|
+
downloadResponse.on("finish", () => {
|
|
182
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
183
|
+
});
|
|
184
|
+
downloadResponse.on("error", (err) => {
|
|
185
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
186
|
+
});
|
|
187
|
+
} else if (uploadResponse) {
|
|
188
|
+
uploadResponse.on("finish", () => {
|
|
189
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
190
|
+
});
|
|
191
|
+
uploadResponse.on("error", (err) => {
|
|
192
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
163
195
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
196
|
+
try {
|
|
197
|
+
const res = executeHttp1Request(config.fetchOptions, mainConfig, config.options, perform, d_options.fs, streamResponse, downloadResponse, uploadResponse);
|
|
198
|
+
if (streamResponse) {
|
|
199
|
+
return streamResponse;
|
|
200
|
+
} else if (downloadResponse) {
|
|
201
|
+
return downloadResponse;
|
|
202
|
+
} else if (uploadResponse) {
|
|
203
|
+
return uploadResponse;
|
|
204
|
+
}
|
|
205
|
+
const response = await res;
|
|
206
|
+
if (proxyManager && selectedProxy) {
|
|
207
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
208
|
+
}
|
|
209
|
+
if (cache && !isStream && !isDownload && !isUpload) {
|
|
210
|
+
if (response.status === 304 && cachedEntry) {
|
|
211
|
+
const responseHeaders = response.headers instanceof RezoHeaders ? Object.fromEntries(response.headers.entries()) : response.headers;
|
|
212
|
+
const updatedCached = cache.updateRevalidated(method, requestUrl, responseHeaders, requestHeaders);
|
|
213
|
+
if (updatedCached) {
|
|
214
|
+
return buildCachedRezoResponse(updatedCached, mainConfig);
|
|
215
|
+
}
|
|
216
|
+
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
217
|
+
}
|
|
218
|
+
if (response.status >= 200 && response.status < 300) {
|
|
219
|
+
cache.set(method, requestUrl, response, requestHeaders);
|
|
171
220
|
}
|
|
172
|
-
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
173
221
|
}
|
|
174
|
-
|
|
175
|
-
|
|
222
|
+
return response;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (proxyManager && selectedProxy) {
|
|
225
|
+
proxyManager.reportFailure(selectedProxy, error);
|
|
176
226
|
}
|
|
227
|
+
throw error;
|
|
177
228
|
}
|
|
178
|
-
return response;
|
|
179
229
|
}
|
|
180
230
|
async function executeHttp1Request(fetchOptions, config, options, perform, fs, streamResult, downloadResult, uploadResult) {
|
|
181
231
|
let requestCount = 0;
|
package/dist/adapters/http2.cjs
CHANGED
|
@@ -308,11 +308,27 @@ async function executeRequest(options, defaultOptions, jar) {
|
|
|
308
308
|
if (!options.responseType) {
|
|
309
309
|
options.responseType = "auto";
|
|
310
310
|
}
|
|
311
|
-
const d_options = await getDefaultConfig(defaultOptions);
|
|
311
|
+
const d_options = await getDefaultConfig(defaultOptions, defaultOptions._proxyManager);
|
|
312
312
|
const configResult = prepareHTTPOptions(options, jar, { defaultOptions: d_options });
|
|
313
313
|
let mainConfig = configResult.config;
|
|
314
314
|
const fetchOptions = configResult.fetchOptions;
|
|
315
|
+
const { proxyManager } = configResult;
|
|
315
316
|
const perform = new RezoPerformance;
|
|
317
|
+
let selectedProxy = null;
|
|
318
|
+
if (proxyManager) {
|
|
319
|
+
const requestUrl = typeof fetchOptions.url === "string" ? fetchOptions.url : fetchOptions.url?.toString() || "";
|
|
320
|
+
selectedProxy = proxyManager.next(requestUrl);
|
|
321
|
+
if (selectedProxy) {
|
|
322
|
+
fetchOptions.proxy = {
|
|
323
|
+
protocol: selectedProxy.protocol,
|
|
324
|
+
host: selectedProxy.host,
|
|
325
|
+
port: selectedProxy.port,
|
|
326
|
+
auth: selectedProxy.auth
|
|
327
|
+
};
|
|
328
|
+
} else if (proxyManager.config.failWithoutProxy) {
|
|
329
|
+
throw new RezoError("No proxy available: All proxies exhausted or URL did not match whitelist/blacklist", mainConfig, "UNQ_NO_PROXY_AVAILABLE", fetchOptions);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
316
332
|
const cacheOption = options.cache;
|
|
317
333
|
const method = (options.method || "GET").toUpperCase();
|
|
318
334
|
const requestUrl = typeof fetchOptions.url === "string" ? fetchOptions.url : fetchOptions.url?.toString() || "";
|
|
@@ -368,29 +384,63 @@ async function executeRequest(options, defaultOptions, jar) {
|
|
|
368
384
|
const url = typeof fetchOptions.url === "string" ? fetchOptions.url : fetchOptions.url?.toString() || "";
|
|
369
385
|
uploadResponse = new UploadResponse(url);
|
|
370
386
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
387
|
+
if (proxyManager && selectedProxy) {
|
|
388
|
+
if (streamResponse) {
|
|
389
|
+
streamResponse.on("finish", () => {
|
|
390
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
391
|
+
});
|
|
392
|
+
streamResponse.on("error", (err) => {
|
|
393
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
394
|
+
});
|
|
395
|
+
} else if (downloadResponse) {
|
|
396
|
+
downloadResponse.on("finish", () => {
|
|
397
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
398
|
+
});
|
|
399
|
+
downloadResponse.on("error", (err) => {
|
|
400
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
401
|
+
});
|
|
402
|
+
} else if (uploadResponse) {
|
|
403
|
+
uploadResponse.on("finish", () => {
|
|
404
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
405
|
+
});
|
|
406
|
+
uploadResponse.on("error", (err) => {
|
|
407
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
378
410
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
411
|
+
try {
|
|
412
|
+
const res = executeHttp2Request(fetchOptions, mainConfig, options, perform, fs, streamResponse, downloadResponse, uploadResponse);
|
|
413
|
+
if (streamResponse) {
|
|
414
|
+
return streamResponse;
|
|
415
|
+
} else if (downloadResponse) {
|
|
416
|
+
return downloadResponse;
|
|
417
|
+
} else if (uploadResponse) {
|
|
418
|
+
return uploadResponse;
|
|
419
|
+
}
|
|
420
|
+
const response = await res;
|
|
421
|
+
if (proxyManager && selectedProxy) {
|
|
422
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
423
|
+
}
|
|
424
|
+
if (cache && !isStream && !isDownload && !isUpload) {
|
|
425
|
+
if (response.status === 304 && cachedEntry) {
|
|
426
|
+
const responseHeaders = response.headers instanceof RezoHeaders ? Object.fromEntries(response.headers.entries()) : response.headers;
|
|
427
|
+
const updatedCached = cache.updateRevalidated(method, requestUrl, responseHeaders, requestHeaders);
|
|
428
|
+
if (updatedCached) {
|
|
429
|
+
return buildCachedRezoResponse(updatedCached, mainConfig);
|
|
430
|
+
}
|
|
431
|
+
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
432
|
+
}
|
|
433
|
+
if (response.status >= 200 && response.status < 300) {
|
|
434
|
+
cache.set(method, requestUrl, response, requestHeaders);
|
|
386
435
|
}
|
|
387
|
-
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
388
436
|
}
|
|
389
|
-
|
|
390
|
-
|
|
437
|
+
return response;
|
|
438
|
+
} catch (error) {
|
|
439
|
+
if (proxyManager && selectedProxy) {
|
|
440
|
+
proxyManager.reportFailure(selectedProxy, error);
|
|
391
441
|
}
|
|
442
|
+
throw error;
|
|
392
443
|
}
|
|
393
|
-
return response;
|
|
394
444
|
}
|
|
395
445
|
async function executeHttp2Request(fetchOptions, config, options, perform, fs, streamResult, downloadResult, uploadResult) {
|
|
396
446
|
let requestCount = 0;
|
package/dist/adapters/http2.js
CHANGED
|
@@ -308,11 +308,27 @@ export async function executeRequest(options, defaultOptions, jar) {
|
|
|
308
308
|
if (!options.responseType) {
|
|
309
309
|
options.responseType = "auto";
|
|
310
310
|
}
|
|
311
|
-
const d_options = await getDefaultConfig(defaultOptions);
|
|
311
|
+
const d_options = await getDefaultConfig(defaultOptions, defaultOptions._proxyManager);
|
|
312
312
|
const configResult = prepareHTTPOptions(options, jar, { defaultOptions: d_options });
|
|
313
313
|
let mainConfig = configResult.config;
|
|
314
314
|
const fetchOptions = configResult.fetchOptions;
|
|
315
|
+
const { proxyManager } = configResult;
|
|
315
316
|
const perform = new RezoPerformance;
|
|
317
|
+
let selectedProxy = null;
|
|
318
|
+
if (proxyManager) {
|
|
319
|
+
const requestUrl = typeof fetchOptions.url === "string" ? fetchOptions.url : fetchOptions.url?.toString() || "";
|
|
320
|
+
selectedProxy = proxyManager.next(requestUrl);
|
|
321
|
+
if (selectedProxy) {
|
|
322
|
+
fetchOptions.proxy = {
|
|
323
|
+
protocol: selectedProxy.protocol,
|
|
324
|
+
host: selectedProxy.host,
|
|
325
|
+
port: selectedProxy.port,
|
|
326
|
+
auth: selectedProxy.auth
|
|
327
|
+
};
|
|
328
|
+
} else if (proxyManager.config.failWithoutProxy) {
|
|
329
|
+
throw new RezoError("No proxy available: All proxies exhausted or URL did not match whitelist/blacklist", mainConfig, "UNQ_NO_PROXY_AVAILABLE", fetchOptions);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
316
332
|
const cacheOption = options.cache;
|
|
317
333
|
const method = (options.method || "GET").toUpperCase();
|
|
318
334
|
const requestUrl = typeof fetchOptions.url === "string" ? fetchOptions.url : fetchOptions.url?.toString() || "";
|
|
@@ -368,29 +384,63 @@ export async function executeRequest(options, defaultOptions, jar) {
|
|
|
368
384
|
const url = typeof fetchOptions.url === "string" ? fetchOptions.url : fetchOptions.url?.toString() || "";
|
|
369
385
|
uploadResponse = new UploadResponse(url);
|
|
370
386
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
387
|
+
if (proxyManager && selectedProxy) {
|
|
388
|
+
if (streamResponse) {
|
|
389
|
+
streamResponse.on("finish", () => {
|
|
390
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
391
|
+
});
|
|
392
|
+
streamResponse.on("error", (err) => {
|
|
393
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
394
|
+
});
|
|
395
|
+
} else if (downloadResponse) {
|
|
396
|
+
downloadResponse.on("finish", () => {
|
|
397
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
398
|
+
});
|
|
399
|
+
downloadResponse.on("error", (err) => {
|
|
400
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
401
|
+
});
|
|
402
|
+
} else if (uploadResponse) {
|
|
403
|
+
uploadResponse.on("finish", () => {
|
|
404
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
405
|
+
});
|
|
406
|
+
uploadResponse.on("error", (err) => {
|
|
407
|
+
proxyManager.reportFailure(selectedProxy, err);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
378
410
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
411
|
+
try {
|
|
412
|
+
const res = executeHttp2Request(fetchOptions, mainConfig, options, perform, fs, streamResponse, downloadResponse, uploadResponse);
|
|
413
|
+
if (streamResponse) {
|
|
414
|
+
return streamResponse;
|
|
415
|
+
} else if (downloadResponse) {
|
|
416
|
+
return downloadResponse;
|
|
417
|
+
} else if (uploadResponse) {
|
|
418
|
+
return uploadResponse;
|
|
419
|
+
}
|
|
420
|
+
const response = await res;
|
|
421
|
+
if (proxyManager && selectedProxy) {
|
|
422
|
+
proxyManager.reportSuccess(selectedProxy);
|
|
423
|
+
}
|
|
424
|
+
if (cache && !isStream && !isDownload && !isUpload) {
|
|
425
|
+
if (response.status === 304 && cachedEntry) {
|
|
426
|
+
const responseHeaders = response.headers instanceof RezoHeaders ? Object.fromEntries(response.headers.entries()) : response.headers;
|
|
427
|
+
const updatedCached = cache.updateRevalidated(method, requestUrl, responseHeaders, requestHeaders);
|
|
428
|
+
if (updatedCached) {
|
|
429
|
+
return buildCachedRezoResponse(updatedCached, mainConfig);
|
|
430
|
+
}
|
|
431
|
+
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
432
|
+
}
|
|
433
|
+
if (response.status >= 200 && response.status < 300) {
|
|
434
|
+
cache.set(method, requestUrl, response, requestHeaders);
|
|
386
435
|
}
|
|
387
|
-
return buildCachedRezoResponse(cachedEntry, mainConfig);
|
|
388
436
|
}
|
|
389
|
-
|
|
390
|
-
|
|
437
|
+
return response;
|
|
438
|
+
} catch (error) {
|
|
439
|
+
if (proxyManager && selectedProxy) {
|
|
440
|
+
proxyManager.reportFailure(selectedProxy, error);
|
|
391
441
|
}
|
|
442
|
+
throw error;
|
|
392
443
|
}
|
|
393
|
-
return response;
|
|
394
444
|
}
|
|
395
445
|
async function executeHttp2Request(fetchOptions, config, options, perform, fs, streamResult, downloadResult, uploadResult) {
|
|
396
446
|
let requestCount = 0;
|
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_y2qidi = require('./picker.cjs');
|
|
2
|
+
exports.detectRuntime = _mod_y2qidi.detectRuntime;
|
|
3
|
+
exports.getAdapterCapabilities = _mod_y2qidi.getAdapterCapabilities;
|
|
4
|
+
exports.buildAdapterContext = _mod_y2qidi.buildAdapterContext;
|
|
5
|
+
exports.getAvailableAdapters = _mod_y2qidi.getAvailableAdapters;
|
|
6
|
+
exports.selectAdapter = _mod_y2qidi.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_hwn1pb = require('./lru-cache.cjs');
|
|
2
|
+
exports.LRUCache = _mod_hwn1pb.LRUCache;;
|
|
3
|
+
const _mod_v5202w = require('./dns-cache.cjs');
|
|
4
|
+
exports.DNSCache = _mod_v5202w.DNSCache;
|
|
5
|
+
exports.getGlobalDNSCache = _mod_v5202w.getGlobalDNSCache;
|
|
6
|
+
exports.resetGlobalDNSCache = _mod_v5202w.resetGlobalDNSCache;;
|
|
7
|
+
const _mod_j87jnr = require('./response-cache.cjs');
|
|
8
|
+
exports.ResponseCache = _mod_j87jnr.ResponseCache;
|
|
9
|
+
exports.normalizeResponseCacheConfig = _mod_j87jnr.normalizeResponseCacheConfig;;
|
|
10
|
+
const _mod_flnkd0 = require('./file-cacher.cjs');
|
|
11
|
+
exports.FileCacher = _mod_flnkd0.FileCacher;;
|
|
12
|
+
const _mod_jkccmq = require('./url-store.cjs');
|
|
13
|
+
exports.UrlStore = _mod_jkccmq.UrlStore;;
|