From b1a979d698d3184b0ed5bb494a6a5ac838c3450d Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Fri, 6 May 2016 10:09:39 -0700 Subject: [PATCH 1/3] add http2 support back --- lib/agent.js | 11 ++++++----- package.json | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) 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/package.json b/package.json index c3b4ab5..3cead3a 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.2" }, "devDependencies": { "alpha-sort": "1.0.2", From f1f4930072fcfc265cafee170aae2af548f706a5 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Wed, 18 May 2016 11:58:26 -0700 Subject: [PATCH 2/3] package: bump spdy --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6961852..5b8d2ef 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "socket.io-client": "1.4.5", "split-array": "1.0.1", "text-table": "0.2.0", - "spdy": "3.3.2" + "spdy": "3.3.3" }, "devDependencies": { "alpha-sort": "1.0.2", From 21ea9859a2b4c27fd4d9d2b815e7da531d96966d Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Wed, 18 May 2016 11:58:34 -0700 Subject: [PATCH 3/3] index: simplify `_fetch` --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); } }