diff --git a/lib/agent.js b/lib/agent.js index 84debbc..bbb8c07 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -1,4 +1,6 @@ +import http2 from 'spdy'; import fetch from 'node-fetch'; +import { parse } from 'url'; /** * Returns a `fetch` version with a similar @@ -14,17 +16,16 @@ import fetch from 'node-fetch'; export default class Agent { constructor (url, { debug } = {}) { this._url = url; + this._host = parse(url).host; this._debug = debug; this._initAgent(); } _initAgent () { - /* - this._agent = https.createAgent({ + this._agent = http2.createAgent({ host: this._host, port: 443 }).once('error', (err) => this._onError(err)); - */ } _onError (err) { @@ -43,7 +44,7 @@ export default class Agent { } const { body } = opts; - // opts.agent = this._agent; + opts.agent = this._agent; if (body && 'object' === typeof body && 'function' !== typeof body.pipe) { opts.headers['Content-Type'] = 'application/json'; @@ -59,6 +60,6 @@ export default class Agent { close () { if (this._debug) console.log('> [debug] closing agent'); - // return this._agent.close(); + return this._agent.close(); } } diff --git a/lib/index.js b/lib/index.js index c6c92bd..85dac79 100644 --- a/lib/index.js +++ b/lib/index.js @@ -278,10 +278,10 @@ export default class Now extends EventEmitter { return this._syncAmount; } - async _fetch (_url, opts = {}) { + _fetch (_url, opts = {}) { opts.headers = opts.headers || {}; opts.headers.authorization = `Bearer ${this._token}`; - return await this._agent.fetch(_url, opts); + return this._agent.fetch(_url, opts); } } diff --git a/package.json b/package.json index b1afda5..184f362 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "retry": "0.9.0", "socket.io-client": "1.4.5", "split-array": "1.0.1", - "text-table": "0.2.0" + "text-table": "0.2.0", + "spdy": "3.3.3" }, "devDependencies": { "alpha-sort": "1.0.2",