Browse Source

don't use http2 agent when url is http (#76)

master
Naoyuki Kanezawa 9 years ago
committed by Guillermo Rauch
parent
commit
15d6a9d621
  1. 8
      lib/agent.js

8
lib/agent.js

@ -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();
}
}

Loading…
Cancel
Save