UNPKG

gads

Version:

An unofficial JS client library for the SOAP-based DFP Ads API

55 lines 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Proxy { constructor(config) { // Convert string config value to ProxyConfig if (typeof config === 'string') { config = this.getProxyConfigFromString(config); } // Apply config properties to instance this.protocol = config.protocol; this.hostname = config.hostname; this.port = config.port; this.path = config.path; this.username = config.username; this.password = config.password; this.ca = config.ca; this.disableCertificateValidation = config.disableCertificateValidation; } getProxyInfo() { let hostname = this.hostname; if (this.username) { hostname = '@' + hostname; if (this.password) { hostname = ':' + this.password + hostname; } hostname = this.username + hostname; } return { tunnel: false, proxy: { hostname, port: (this.port || '') + (this.path || ''), protocol: this.protocol.substr(0, 5) === 'https' ? 'https:' : 'http:' }, ca: (this.disableCertificateValidation) ? undefined : this.ca }; } getProxyConfigFromString(config) { const regex = /^(?:(https?):\/\/)?(?:([^:]+):([^@]+)@)?([^:\/]+)(?::([\d]+))?(.*)$/i; const arr = regex.exec(config); if (!arr) { throw new Error('Could not parse proxy config'); } return { protocol: arr[1], username: arr[2], password: arr[3], hostname: arr[4], port: arr[5] ? +arr[5] : undefined, path: arr[6] }; } } exports.Proxy = Proxy; //# sourceMappingURL=proxy.js.map