Skip to content

Commit f075389

Browse files
author
Taois
committed
feat: reqs去除继承代理
1 parent 3d77f86 commit f075389

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

utils/req.js

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -110,50 +110,50 @@ export const reqs = new _axios.create({
110110
});
111111

112112
// Add System Proxy & DOH interceptor to reqs as well
113-
reqs.interceptors.request.use(async config => {
114-
if (!config.url) return config;
115-
try {
116-
// 1. Check System Proxy
117-
const proxy = await getSystemProxy();
118-
if (proxy) {
119-
const agent = new HttpsProxyAgent(proxy);
120-
config.httpsAgent = agent;
121-
config.proxy = false;
122-
return config;
123-
}
124-
125-
// 2. DOH
126-
let fullUrl = config.url;
127-
if (config.baseURL && !/^https?:\/\//i.test(fullUrl)) {
128-
try {
129-
const parsed = new URL(fullUrl, config.baseURL);
130-
fullUrl = parsed.toString();
131-
} catch (e) {
132-
}
133-
}
134-
const urlObj = new URL(fullUrl);
135-
const hostname = urlObj.hostname;
136-
if (!hostname || /^(\d{1,3}\.){3}\d{1,3}$/.test(hostname) || hostname === 'localhost') return config;
137-
const ip = await resolveDoh(hostname);
138-
if (ip && ip !== hostname) {
139-
if (!config.headers) config.headers = {};
140-
let hasHost = false;
141-
const keys = Object.keys(config.headers);
142-
for (const k of keys) {
143-
if (k.toLowerCase() === 'host') {
144-
hasHost = true;
145-
break;
146-
}
147-
}
148-
if (!hasHost) config.headers.Host = hostname;
149-
urlObj.hostname = ip;
150-
config.url = urlObj.toString();
151-
if (config.baseURL) delete config.baseURL;
152-
}
153-
} catch (e) {
154-
}
155-
return config;
156-
});
113+
// reqs.interceptors.request.use(async config => {
114+
// if (!config.url) return config;
115+
// try {
116+
// // 1. Check System Proxy
117+
// const proxy = await getSystemProxy();
118+
// if (proxy) {
119+
// const agent = new HttpsProxyAgent(proxy);
120+
// config.httpsAgent = agent;
121+
// config.proxy = false;
122+
// return config;
123+
// }
124+
//
125+
// // 2. DOH
126+
// let fullUrl = config.url;
127+
// if (config.baseURL && !/^https?:\/\//i.test(fullUrl)) {
128+
// try {
129+
// const parsed = new URL(fullUrl, config.baseURL);
130+
// fullUrl = parsed.toString();
131+
// } catch (e) {
132+
// }
133+
// }
134+
// const urlObj = new URL(fullUrl);
135+
// const hostname = urlObj.hostname;
136+
// if (!hostname || /^(\d{1,3}\.){3}\d{1,3}$/.test(hostname) || hostname === 'localhost') return config;
137+
// const ip = await resolveDoh(hostname);
138+
// if (ip && ip !== hostname) {
139+
// if (!config.headers) config.headers = {};
140+
// let hasHost = false;
141+
// const keys = Object.keys(config.headers);
142+
// for (const k of keys) {
143+
// if (k.toLowerCase() === 'host') {
144+
// hasHost = true;
145+
// break;
146+
// }
147+
// }
148+
// if (!hasHost) config.headers.Host = hostname;
149+
// urlObj.hostname = ip;
150+
// config.url = urlObj.toString();
151+
// if (config.baseURL) delete config.baseURL;
152+
// }
153+
// } catch (e) {
154+
// }
155+
// return config;
156+
// });
157157

158158
// 导出默认的HTTP请求客户端
159159
export default req;

0 commit comments

Comments
 (0)