feat: x-prefer-proxy

This commit is contained in:
DIYgod
2024-07-13 18:20:28 +08:00
parent d53c5e41dc
commit 9fbbed6b04
2 changed files with 9 additions and 5 deletions
+7 -3
View File
@@ -7,13 +7,17 @@ const rofetch = createFetch().create({
retry: config.requestRetry,
retryDelay: 1000,
// timeout: config.requestTimeout,
onResponseError({ request, options }) {
onResponseError({ request, response, options }) {
if (options.retry) {
logger.warn(`Request ${request} remaining retry attempts: ${options.retry}`);
logger.warn(`Request ${request} with error ${response.status} remaining retry attempts: ${options.retry}`);
if (!options.headers) {
options.headers = {};
}
options.headers['x-retry'] = options.retry;
if (options.headers instanceof Headers) {
options.headers.set('x-prefer-proxy', '1');
} else {
options.headers['x-prefer-proxy'] = '1';
}
}
},
onRequestError({ request, error }) {
+2 -2
View File
@@ -41,9 +41,9 @@ const wrappedFetch: typeof undici.fetch = async (input: RequestInfo, init?: Requ
}
let isRetry = false;
if (request.headers.get('x-retry')) {
if (request.headers.get('x-prefer-proxy')) {
isRetry = true;
request.headers.delete('x-retry');
request.headers.delete('x-prefer-proxy');
}
// proxy