提交 ab37ff32 编写于 作者: YXL76's avatar YXL76

use `axios` to replace `request`

上级 123e1375
此差异已折叠。
......@@ -44,8 +44,7 @@
"axios": "^0.20.0",
"express": "^4.17.1",
"express-fileupload": "^1.1.9",
"pac-proxy-agent": "^4.0.0",
"request": "^2.88.0"
"pac-proxy-agent": "^4.0.0"
},
"devDependencies": {
"@types/node": "14.11.2",
......
const encrypt = require('./crypto')
const request = require('request')
const axios = require('axios')
const queryString = require('querystring')
const PacProxyAgent = require('pac-proxy-agent')
const zlib = require('zlib')
const http = require('http')
const https = require('https')
// request.debug = true // 开启可看到更详细信息
......@@ -114,23 +116,23 @@ const createRequest = (method, url, data, options) => {
method: method,
url: url,
headers: headers,
body: queryString.stringify(data),
data: queryString.stringify(data),
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true }),
}
if (options.crypto === 'eapi') settings.encoding = null
if (/\.pac$/i.test(options.proxy)) {
settings.agent = new PacProxyAgent(options.proxy)
settings.httpAgent = new PacProxyAgent(options.proxy)
settings.httpsAgent = new PacProxyAgent(options.proxy)
} else {
settings.proxy = options.proxy
}
request(settings, (err, res, body) => {
if (err) {
answer.status = 502
answer.body = { code: 502, msg: err.stack }
reject(answer)
} else {
axios(settings)
.then((res) => {
const body = res.data
answer.cookie = (res.headers['set-cookie'] || []).map((x) =>
x.replace(/\s*Domain=[^(;|$)]+;*/, ''),
)
......@@ -172,8 +174,12 @@ const createRequest = (method, url, data, options) => {
100 < answer.status && answer.status < 600 ? answer.status : 400
if (answer.status == 200) resolve(answer)
else reject(answer)
}
})
})
.catch((err) => {
answer.status = 502
answer.body = { code: 502, msg: err }
reject(answer)
})
})
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册