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