|
|
@ -16,12 +16,16 @@ import { parse } from 'url'; |
|
|
|
export default class Agent { |
|
|
|
constructor (url, { debug } = {}) { |
|
|
|
this._url = url; |
|
|
|
this._host = parse(url).host; |
|
|
|
const { protocol, host } = parse(url); |
|
|
|
this._protocol = protocol; |
|
|
|
this._host = host; |
|
|
|
this._debug = debug; |
|
|
|
this._initAgent(); |
|
|
|
} |
|
|
|
|
|
|
|
_initAgent () { |
|
|
|
if ('https:' !== this._protocol) return; |
|
|
|
|
|
|
|
this._agent = http2.createAgent({ |
|
|
|
host: this._host, |
|
|
|
port: 443 |
|
|
@ -60,6 +64,6 @@ export default class Agent { |
|
|
|
|
|
|
|
close () { |
|
|
|
if (this._debug) console.log('> [debug] closing agent'); |
|
|
|
return this._agent.close(); |
|
|
|
if (this._agent) return this._agent.close(); |
|
|
|
} |
|
|
|
} |
|
|
|