surgio
Version:
Generating rules for Surge, Clash, Quantumult like a PRO
60 lines • 2.16 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUserAgent = void 0;
const got_1 = __importDefault(require("got"));
const http_1 = __importDefault(require("http"));
const https_1 = __importDefault(require("https"));
const hpagent_1 = require("hpagent");
const constant_1 = require("../constant");
const env_flag_1 = require("./env-flag");
const httpProxy = hasHTTPProxy();
const httpsProxy = hasHTTPSProxy();
const pkg = require('../../package.json');
const agent = !!httpProxy || !!httpsProxy
? {
http: httpProxy
? new hpagent_1.HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: httpProxy,
})
: new http_1.default.Agent({ keepAlive: true }),
https: httpsProxy
? new hpagent_1.HttpsProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: httpsProxy,
})
: new https_1.default.Agent({ keepAlive: true }),
}
: {
http: new http_1.default.Agent({ keepAlive: true }),
https: new https_1.default.Agent({ keepAlive: true }),
};
const getUserAgent = (str) => `${str ? str + ' ' : ''}${constant_1.NETWORK_SURGIO_UA}/${pkg.version}`;
exports.getUserAgent = getUserAgent;
const httpClient = got_1.default.extend({
timeout: (0, env_flag_1.getNetworkTimeout)(),
retry: (0, env_flag_1.getNetworkRetry)(),
headers: {
'user-agent': (0, exports.getUserAgent)(),
},
agent,
});
function hasHTTPProxy() {
return process.env.HTTP_PROXY || process.env.http_proxy;
}
function hasHTTPSProxy() {
return process.env.HTTPS_PROXY || process.env.https_proxy;
}
exports.default = httpClient;
//# sourceMappingURL=http-client.js.map