|
4 | 4 | import url = require("url");
|
5 | 5 | import http = require("http");
|
6 | 6 | import https = require("https");
|
7 |
| -import tunnel = require("tunnel"); |
8 | 7 | import ifm = require('./Interfaces');
|
9 |
| -import fs = require('fs'); |
| 8 | +let fs: any; |
| 9 | +let tunnel: any; |
10 | 10 |
|
11 | 11 | export enum HttpCodes {
|
12 | 12 | OK = 200,
|
@@ -122,17 +122,22 @@ export class HttpClient implements ifm.IHttpClient {
|
122 | 122 |
|
123 | 123 | this._certConfig = requestOptions.cert;
|
124 | 124 |
|
125 |
| - // cache the cert content into memory, so we don't have to read it from disk every time |
126 |
| - if (this._certConfig && this._certConfig.caFile && fs.existsSync(this._certConfig.caFile)) { |
127 |
| - this._ca = fs.readFileSync(this._certConfig.caFile, 'utf8'); |
128 |
| - } |
129 |
| - |
130 |
| - if (this._certConfig && this._certConfig.certFile && fs.existsSync(this._certConfig.certFile)) { |
131 |
| - this._cert = fs.readFileSync(this._certConfig.certFile, 'utf8'); |
132 |
| - } |
| 125 | + if (this._certConfig) { |
| 126 | + // If using cert, need fs |
| 127 | + fs = require('fs'); |
133 | 128 |
|
134 |
| - if (this._certConfig && this._certConfig.keyFile && fs.existsSync(this._certConfig.keyFile)) { |
135 |
| - this._key = fs.readFileSync(this._certConfig.keyFile, 'utf8'); |
| 129 | + // cache the cert content into memory, so we don't have to read it from disk every time |
| 130 | + if (this._certConfig.caFile && fs.existsSync(this._certConfig.caFile)) { |
| 131 | + this._ca = fs.readFileSync(this._certConfig.caFile, 'utf8'); |
| 132 | + } |
| 133 | + |
| 134 | + if (this._certConfig.certFile && fs.existsSync(this._certConfig.certFile)) { |
| 135 | + this._cert = fs.readFileSync(this._certConfig.certFile, 'utf8'); |
| 136 | + } |
| 137 | + |
| 138 | + if (this._certConfig.keyFile && fs.existsSync(this._certConfig.keyFile)) { |
| 139 | + this._key = fs.readFileSync(this._certConfig.keyFile, 'utf8'); |
| 140 | + } |
136 | 141 | }
|
137 | 142 |
|
138 | 143 | if (requestOptions.allowRedirects != null) {
|
@@ -437,7 +442,12 @@ export class HttpClient implements ifm.IHttpClient {
|
437 | 442 | }
|
438 | 443 |
|
439 | 444 | if (useProxy) {
|
440 |
| - const agentOptions: tunnel.TunnelOptions = { |
| 445 | + // If using proxy, need tunnel |
| 446 | + if (!tunnel) { |
| 447 | + tunnel = require('tunnel'); |
| 448 | + } |
| 449 | + |
| 450 | + const agentOptions = { |
441 | 451 | maxSockets: maxSockets,
|
442 | 452 | keepAlive: this._keepAlive,
|
443 | 453 | proxy: {
|
|
0 commit comments