UNPKG

1.59 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.client = exports.setConfig = void 0;
7const urllib_1 = __importDefault(require("urllib"));
8const agentkeepalive_1 = __importDefault(require("agentkeepalive"));
9const getUserAgent_1 = require("./common/utils/getUserAgent");
10const initOptions_1 = __importDefault(require("./common/client/initOptions"));
11const HttpsAgentKeepalive = agentkeepalive_1.default.HttpsAgent;
12const globalHttpAgent = new agentkeepalive_1.default();
13const globalHttpsAgent = new HttpsAgentKeepalive();
14class Client {
15 constructor(options, ctx) {
16 if (!(this instanceof Client)) {
17 return new Client(options, ctx);
18 }
19 if (options && options.inited) {
20 this.options = options;
21 }
22 else {
23 this.options = initOptions_1.default(options);
24 }
25 // support custom agent and urllib client
26 if (this.options.urllib) {
27 this.urllib = this.options.urllib;
28 }
29 else {
30 this.urllib = urllib_1.default;
31 this.agent = this.options.agent || globalHttpAgent;
32 this.httpsAgent = this.options.httpsAgent || globalHttpsAgent;
33 }
34 this.ctx = ctx;
35 this.userAgent = getUserAgent_1.getUserAgent();
36 }
37}
38let client;
39exports.client = client;
40exports.setConfig = (options, ctx) => {
41 exports.client = client = new Client(options, ctx);
42};