Browse Source

Merge branch 'add/http-2'

master
Guillermo Rauch 9 years ago
parent
commit
f0748bd61b
  1. 11
      lib/agent.js
  2. 4
      lib/index.js
  3. 3
      package.json

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

4
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);
}
}

3
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",

Loading…
Cancel
Save