修复启用代理时,https请求可能被挂起或被转为http的问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { shell, clipboard } from 'electron'
|
||||
import { httpOverHttp, httpsOverHttp } from 'tunnel'
|
||||
import crypto from 'crypto'
|
||||
import { rendererSend, rendererInvoke, NAMES } from '@common/ipc'
|
||||
import { log } from '@common/utils'
|
||||
@@ -451,12 +452,33 @@ export const setWindowSize = (width, height) => rendererSend(NAMES.mainWindow.se
|
||||
|
||||
export const getProxyInfo = () => {
|
||||
return proxy.enable && proxy.host
|
||||
? `http://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port};`
|
||||
? `http://${proxy.username}:${proxy.password}@${proxy.host}:${proxy.port}`
|
||||
: proxy.envProxy
|
||||
? `http://${proxy.envProxy.host}:${proxy.envProxy.port};`
|
||||
? `http://${proxy.envProxy.host}:${proxy.envProxy.port}`
|
||||
: undefined
|
||||
}
|
||||
|
||||
const httpsRxp = /^https:/
|
||||
export const getRequestAgent = url => {
|
||||
let options
|
||||
if (proxy.enable && proxy.host) {
|
||||
options = {
|
||||
proxy: {
|
||||
host: proxy.host,
|
||||
port: proxy.port,
|
||||
},
|
||||
}
|
||||
} else if (proxy.envProxy) {
|
||||
options = {
|
||||
proxy: {
|
||||
host: proxy.envProxy.host,
|
||||
port: proxy.envProxy.port,
|
||||
},
|
||||
}
|
||||
}
|
||||
return options ? (httpsRxp.test(url) ? httpsOverHttp : httpOverHttp)(options) : undefined
|
||||
}
|
||||
|
||||
|
||||
export const assertApiSupport = source => qualityList.value[source] != undefined
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { debugRequest } from './env'
|
||||
import { requestMsg } from './message'
|
||||
import { bHh } from './music/options'
|
||||
import { deflateRaw } from 'zlib'
|
||||
import { getProxyInfo } from './index'
|
||||
import { getRequestAgent } from './index'
|
||||
// import fs from 'fs'
|
||||
|
||||
const request = (url, options, callback) => {
|
||||
@@ -277,7 +277,7 @@ const fetchData = async(url, method, {
|
||||
method,
|
||||
headers: Object.assign({}, defaultHeaders, headers),
|
||||
timeout,
|
||||
proxy: getProxyInfo(),
|
||||
agent: getRequestAgent(url),
|
||||
json: format === 'json',
|
||||
}, (err, resp, body) => {
|
||||
if (err) return callback(err, null)
|
||||
|
||||
Reference in New Issue
Block a user