From 15d6a9d621376263622beb266f1ef8c564ef9599 Mon Sep 17 00:00:00 2001 From: Naoyuki Kanezawa Date: Thu, 23 Jun 2016 01:29:09 +0900 Subject: [PATCH] don't use http2 agent when url is http (#76) --- lib/agent.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/agent.js b/lib/agent.js index bbb8c07..60baa13 100644 --- a/lib/agent.js +++ b/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(); } }