artifact-engine 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Engine/artifactEngine.d.ts +12 -12
- package/Engine/artifactEngine.js +166 -166
- package/Engine/artifactEngineOptions.d.ts +8 -8
- package/Engine/artifactEngineOptions.js +13 -15
- package/Engine/cilogger.d.ts +6 -6
- package/Engine/cilogger.js +44 -46
- package/Engine/index.d.ts +2 -2
- package/Engine/index.js +6 -8
- package/Engine/logger.d.ts +13 -13
- package/Engine/logger.js +109 -112
- package/Engine/worker.d.ts +10 -10
- package/Engine/worker.js +49 -51
- package/Models/artifactDownloadTicket.d.ts +11 -11
- package/Models/artifactDownloadTicket.js +5 -7
- package/Models/artifactItem.d.ts +12 -12
- package/Models/artifactItem.js +8 -10
- package/Models/artifactprovider.d.ts +10 -11
- package/Models/artifactprovider.js +2 -3
- package/Models/constants.d.ts +3 -3
- package/Models/constants.js +6 -8
- package/Models/index.d.ts +6 -6
- package/Models/index.js +12 -14
- package/Models/itemType.d.ts +5 -5
- package/Models/itemType.js +8 -10
- package/Models/ticketState.d.ts +7 -7
- package/Models/ticketState.js +10 -12
- package/Providers/filesystemProvider.d.ts +14 -15
- package/Providers/filesystemProvider.js +123 -123
- package/Providers/index.d.ts +4 -4
- package/Providers/index.js +10 -12
- package/Providers/stubProvider.d.ts +20 -21
- package/Providers/stubProvider.js +85 -88
- package/Providers/typed-rest-client/Handlers.d.ts +4 -4
- package/Providers/typed-rest-client/Handlers.js +10 -12
- package/Providers/typed-rest-client/HttpClient.d.ts +84 -77
- package/Providers/typed-rest-client/HttpClient.js +351 -328
- package/Providers/typed-rest-client/Index.d.ts +0 -1
- package/Providers/typed-rest-client/Index.js +2 -3
- package/Providers/typed-rest-client/Interfaces.d.ts +39 -38
- package/Providers/typed-rest-client/Interfaces.js +3 -4
- package/Providers/typed-rest-client/RestClient.d.ts +73 -27
- package/Providers/typed-rest-client/RestClient.js +186 -134
- package/Providers/typed-rest-client/Util.d.ts +7 -1
- package/Providers/typed-rest-client/Util.js +24 -18
- package/Providers/typed-rest-client/handlers/basiccreds.d.ts +9 -9
- package/Providers/typed-rest-client/handlers/basiccreds.js +23 -20
- package/Providers/typed-rest-client/handlers/bearertoken.d.ts +8 -8
- package/Providers/typed-rest-client/handlers/bearertoken.js +22 -19
- package/Providers/typed-rest-client/handlers/ntlm.d.ts +13 -13
- package/Providers/typed-rest-client/handlers/ntlm.js +115 -96
- package/Providers/typed-rest-client/handlers/personalaccesstoken.d.ts +8 -8
- package/Providers/typed-rest-client/handlers/personalaccesstoken.js +22 -19
- package/Providers/typed-rest-client/opensource/node-http-ntlm/readme.txt +6 -0
- package/Providers/webClient.d.ts +8 -8
- package/Providers/webClient.js +60 -60
- package/Providers/webClientFactory.d.ts +5 -5
- package/Providers/webClientFactory.js +59 -55
- package/Providers/webProvider.d.ts +22 -22
- package/Providers/webProvider.js +128 -116
- package/Providers/zipProvider.d.ts +15 -16
- package/Providers/zipProvider.js +53 -55
- package/Store/artifactItemStore.d.ts +18 -18
- package/Store/artifactItemStore.js +94 -96
- package/Store/index.d.ts +1 -1
- package/Store/index.js +4 -6
- package/Strings/resources.resjson/de-DE/resources.resjson +11 -11
- package/Strings/resources.resjson/en-US/resources.resjson +11 -11
- package/Strings/resources.resjson/es-ES/resources.resjson +11 -11
- package/Strings/resources.resjson/fr-FR/resources.resjson +11 -11
- package/Strings/resources.resjson/it-IT/resources.resjson +11 -11
- package/Strings/resources.resjson/ja-JP/resources.resjson +11 -11
- package/Strings/resources.resjson/ko-KR/resources.resjson +11 -11
- package/Strings/resources.resjson/ru-RU/resources.resjson +11 -11
- package/Strings/resources.resjson/zh-CN/resources.resjson +11 -11
- package/Strings/resources.resjson/zh-TW/resources.resjson +11 -11
- package/npm-shrinkwrap.json +176 -68
- package/package.json +2 -2
|
@@ -1,328 +1,351 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function
|
|
7
|
-
function
|
|
8
|
-
step(
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const url = require("url");
|
|
14
|
-
const http = require("http");
|
|
15
|
-
const https = require("https");
|
|
16
|
-
var tunnel = require("tunnel");
|
|
17
|
-
const fs = require("fs");
|
|
18
|
-
var HttpCodes;
|
|
19
|
-
(function (HttpCodes) {
|
|
20
|
-
HttpCodes[HttpCodes["OK"] = 200] = "OK";
|
|
21
|
-
HttpCodes[HttpCodes["MultipleChoices"] = 300] = "MultipleChoices";
|
|
22
|
-
HttpCodes[HttpCodes["MovedPermanently"] = 301] = "MovedPermanently";
|
|
23
|
-
HttpCodes[HttpCodes["ResourceMoved"] = 302] = "ResourceMoved";
|
|
24
|
-
HttpCodes[HttpCodes["NotModified"] = 304] = "NotModified";
|
|
25
|
-
HttpCodes[HttpCodes["UseProxy"] = 305] = "UseProxy";
|
|
26
|
-
HttpCodes[HttpCodes["SwitchProxy"] = 306] = "SwitchProxy";
|
|
27
|
-
HttpCodes[HttpCodes["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
28
|
-
HttpCodes[HttpCodes["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
29
|
-
HttpCodes[HttpCodes["BadRequest"] = 400] = "BadRequest";
|
|
30
|
-
HttpCodes[HttpCodes["Unauthorized"] = 401] = "Unauthorized";
|
|
31
|
-
HttpCodes[HttpCodes["PaymentRequired"] = 402] = "PaymentRequired";
|
|
32
|
-
HttpCodes[HttpCodes["Forbidden"] = 403] = "Forbidden";
|
|
33
|
-
HttpCodes[HttpCodes["NotFound"] = 404] = "NotFound";
|
|
34
|
-
HttpCodes[HttpCodes["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
35
|
-
HttpCodes[HttpCodes["NotAcceptable"] = 406] = "NotAcceptable";
|
|
36
|
-
HttpCodes[HttpCodes["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
37
|
-
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
|
|
38
|
-
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
|
|
39
|
-
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
|
|
40
|
-
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
|
|
41
|
-
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
|
|
42
|
-
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
|
|
43
|
-
HttpCodes[HttpCodes["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
44
|
-
HttpCodes[HttpCodes["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
45
|
-
})(HttpCodes = exports.HttpCodes || (exports.HttpCodes = {}));
|
|
46
|
-
const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect];
|
|
47
|
-
class HttpClientResponse {
|
|
48
|
-
constructor(message) {
|
|
49
|
-
this.message = message;
|
|
50
|
-
}
|
|
51
|
-
readBody() {
|
|
52
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
let output = '';
|
|
54
|
-
this.message.on('data', (chunk) => {
|
|
55
|
-
output += chunk;
|
|
56
|
-
});
|
|
57
|
-
this.message.on('end', () => {
|
|
58
|
-
resolve(output);
|
|
59
|
-
});
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.HttpClientResponse = HttpClientResponse;
|
|
64
|
-
function isHttps(requestUrl) {
|
|
65
|
-
let parsedUrl = url.parse(requestUrl);
|
|
66
|
-
return parsedUrl.protocol === 'https:';
|
|
67
|
-
}
|
|
68
|
-
exports.isHttps = isHttps;
|
|
69
|
-
var EnvironmentVariables;
|
|
70
|
-
(function (EnvironmentVariables) {
|
|
71
|
-
EnvironmentVariables[EnvironmentVariables["HTTP_PROXY"] = "HTTP_PROXY"] = "HTTP_PROXY";
|
|
72
|
-
EnvironmentVariables[EnvironmentVariables["HTTPS_PROXY"] = "HTTPS_PROXY"] = "HTTPS_PROXY";
|
|
73
|
-
})(EnvironmentVariables || (EnvironmentVariables = {}));
|
|
74
|
-
class HttpClient {
|
|
75
|
-
constructor(userAgent, handlers, requestOptions) {
|
|
76
|
-
this._ignoreSslError = false;
|
|
77
|
-
this._allowRedirects = true;
|
|
78
|
-
this._maxRedirects = 50;
|
|
79
|
-
this._keepAlive = false;
|
|
80
|
-
this._disposed = false;
|
|
81
|
-
this.userAgent = userAgent;
|
|
82
|
-
this.handlers = handlers;
|
|
83
|
-
this.requestOptions = requestOptions;
|
|
84
|
-
if (requestOptions) {
|
|
85
|
-
if (requestOptions.ignoreSslError != null) {
|
|
86
|
-
this._ignoreSslError = requestOptions.ignoreSslError;
|
|
87
|
-
}
|
|
88
|
-
this._socketTimeout = requestOptions.socketTimeout;
|
|
89
|
-
this._httpProxy = requestOptions.proxy;
|
|
90
|
-
if (requestOptions.proxy && requestOptions.proxy.proxyBypassHosts) {
|
|
91
|
-
this._httpProxyBypassHosts = [];
|
|
92
|
-
requestOptions.proxy.proxyBypassHosts.forEach(bypass => {
|
|
93
|
-
this._httpProxyBypassHosts.push(new RegExp(bypass, 'i'));
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
this._certConfig = requestOptions.cert;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
req.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft. All rights reserved.
|
|
3
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
const url = require("url");
|
|
14
|
+
const http = require("http");
|
|
15
|
+
const https = require("https");
|
|
16
|
+
var tunnel = require("tunnel");
|
|
17
|
+
const fs = require("fs");
|
|
18
|
+
var HttpCodes;
|
|
19
|
+
(function (HttpCodes) {
|
|
20
|
+
HttpCodes[HttpCodes["OK"] = 200] = "OK";
|
|
21
|
+
HttpCodes[HttpCodes["MultipleChoices"] = 300] = "MultipleChoices";
|
|
22
|
+
HttpCodes[HttpCodes["MovedPermanently"] = 301] = "MovedPermanently";
|
|
23
|
+
HttpCodes[HttpCodes["ResourceMoved"] = 302] = "ResourceMoved";
|
|
24
|
+
HttpCodes[HttpCodes["NotModified"] = 304] = "NotModified";
|
|
25
|
+
HttpCodes[HttpCodes["UseProxy"] = 305] = "UseProxy";
|
|
26
|
+
HttpCodes[HttpCodes["SwitchProxy"] = 306] = "SwitchProxy";
|
|
27
|
+
HttpCodes[HttpCodes["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
28
|
+
HttpCodes[HttpCodes["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
29
|
+
HttpCodes[HttpCodes["BadRequest"] = 400] = "BadRequest";
|
|
30
|
+
HttpCodes[HttpCodes["Unauthorized"] = 401] = "Unauthorized";
|
|
31
|
+
HttpCodes[HttpCodes["PaymentRequired"] = 402] = "PaymentRequired";
|
|
32
|
+
HttpCodes[HttpCodes["Forbidden"] = 403] = "Forbidden";
|
|
33
|
+
HttpCodes[HttpCodes["NotFound"] = 404] = "NotFound";
|
|
34
|
+
HttpCodes[HttpCodes["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
35
|
+
HttpCodes[HttpCodes["NotAcceptable"] = 406] = "NotAcceptable";
|
|
36
|
+
HttpCodes[HttpCodes["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
37
|
+
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
|
|
38
|
+
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
|
|
39
|
+
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
|
|
40
|
+
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
|
|
41
|
+
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
|
|
42
|
+
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
|
|
43
|
+
HttpCodes[HttpCodes["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
44
|
+
HttpCodes[HttpCodes["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
45
|
+
})(HttpCodes = exports.HttpCodes || (exports.HttpCodes = {}));
|
|
46
|
+
const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect];
|
|
47
|
+
class HttpClientResponse {
|
|
48
|
+
constructor(message) {
|
|
49
|
+
this.message = message;
|
|
50
|
+
}
|
|
51
|
+
readBody() {
|
|
52
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
let output = '';
|
|
54
|
+
this.message.on('data', (chunk) => {
|
|
55
|
+
output += chunk;
|
|
56
|
+
});
|
|
57
|
+
this.message.on('end', () => {
|
|
58
|
+
resolve(output);
|
|
59
|
+
});
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.HttpClientResponse = HttpClientResponse;
|
|
64
|
+
function isHttps(requestUrl) {
|
|
65
|
+
let parsedUrl = url.parse(requestUrl);
|
|
66
|
+
return parsedUrl.protocol === 'https:';
|
|
67
|
+
}
|
|
68
|
+
exports.isHttps = isHttps;
|
|
69
|
+
var EnvironmentVariables;
|
|
70
|
+
(function (EnvironmentVariables) {
|
|
71
|
+
EnvironmentVariables[EnvironmentVariables["HTTP_PROXY"] = "HTTP_PROXY"] = "HTTP_PROXY";
|
|
72
|
+
EnvironmentVariables[EnvironmentVariables["HTTPS_PROXY"] = "HTTPS_PROXY"] = "HTTPS_PROXY";
|
|
73
|
+
})(EnvironmentVariables || (EnvironmentVariables = {}));
|
|
74
|
+
class HttpClient {
|
|
75
|
+
constructor(userAgent, handlers, requestOptions) {
|
|
76
|
+
this._ignoreSslError = false;
|
|
77
|
+
this._allowRedirects = true;
|
|
78
|
+
this._maxRedirects = 50;
|
|
79
|
+
this._keepAlive = false;
|
|
80
|
+
this._disposed = false;
|
|
81
|
+
this.userAgent = userAgent;
|
|
82
|
+
this.handlers = handlers;
|
|
83
|
+
this.requestOptions = requestOptions;
|
|
84
|
+
if (requestOptions) {
|
|
85
|
+
if (requestOptions.ignoreSslError != null) {
|
|
86
|
+
this._ignoreSslError = requestOptions.ignoreSslError;
|
|
87
|
+
}
|
|
88
|
+
this._socketTimeout = requestOptions.socketTimeout;
|
|
89
|
+
this._httpProxy = requestOptions.proxy;
|
|
90
|
+
if (requestOptions.proxy && requestOptions.proxy.proxyBypassHosts) {
|
|
91
|
+
this._httpProxyBypassHosts = [];
|
|
92
|
+
requestOptions.proxy.proxyBypassHosts.forEach(bypass => {
|
|
93
|
+
this._httpProxyBypassHosts.push(new RegExp(bypass, 'i'));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
this._certConfig = requestOptions.cert;
|
|
97
|
+
// cache the cert content into memory, so we don't have to read it from disk every time
|
|
98
|
+
if (this._certConfig && this._certConfig.caFile && fs.existsSync(this._certConfig.caFile)) {
|
|
99
|
+
this._ca = fs.readFileSync(this._certConfig.caFile, 'utf8');
|
|
100
|
+
}
|
|
101
|
+
if (this._certConfig && this._certConfig.certFile && fs.existsSync(this._certConfig.certFile)) {
|
|
102
|
+
this._cert = fs.readFileSync(this._certConfig.certFile, 'utf8');
|
|
103
|
+
}
|
|
104
|
+
if (this._certConfig && this._certConfig.keyFile && fs.existsSync(this._certConfig.keyFile)) {
|
|
105
|
+
this._key = fs.readFileSync(this._certConfig.keyFile, 'utf8');
|
|
106
|
+
}
|
|
107
|
+
if (requestOptions.allowRedirects != null) {
|
|
108
|
+
this._allowRedirects = requestOptions.allowRedirects;
|
|
109
|
+
}
|
|
110
|
+
if (requestOptions.maxRedirects != null) {
|
|
111
|
+
this._maxRedirects = Math.max(requestOptions.maxRedirects, 0);
|
|
112
|
+
}
|
|
113
|
+
if (requestOptions.keepAlive != null) {
|
|
114
|
+
this._keepAlive = requestOptions.keepAlive;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
options(requestUrl, additionalHeaders) {
|
|
119
|
+
return this.request('OPTIONS', requestUrl, null, additionalHeaders || {});
|
|
120
|
+
}
|
|
121
|
+
get(requestUrl, additionalHeaders) {
|
|
122
|
+
return this.request('GET', requestUrl, null, additionalHeaders || {});
|
|
123
|
+
}
|
|
124
|
+
del(requestUrl, additionalHeaders) {
|
|
125
|
+
return this.request('DELETE', requestUrl, null, additionalHeaders || {});
|
|
126
|
+
}
|
|
127
|
+
post(requestUrl, data, additionalHeaders) {
|
|
128
|
+
return this.request('POST', requestUrl, data, additionalHeaders || {});
|
|
129
|
+
}
|
|
130
|
+
patch(requestUrl, data, additionalHeaders) {
|
|
131
|
+
return this.request('PATCH', requestUrl, data, additionalHeaders || {});
|
|
132
|
+
}
|
|
133
|
+
put(requestUrl, data, additionalHeaders) {
|
|
134
|
+
return this.request('PUT', requestUrl, data, additionalHeaders || {});
|
|
135
|
+
}
|
|
136
|
+
head(requestUrl, additionalHeaders) {
|
|
137
|
+
return this.request('HEAD', requestUrl, null, additionalHeaders || {});
|
|
138
|
+
}
|
|
139
|
+
sendStream(verb, requestUrl, stream, additionalHeaders) {
|
|
140
|
+
return this.request(verb, requestUrl, stream, additionalHeaders);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Makes a raw http request.
|
|
144
|
+
* All other methods such as get, post, patch, and request ultimately call this.
|
|
145
|
+
* Prefer get, del, post and patch
|
|
146
|
+
*/
|
|
147
|
+
request(verb, requestUrl, data, headers) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
if (this._disposed) {
|
|
150
|
+
throw new Error("Client has already been disposed");
|
|
151
|
+
}
|
|
152
|
+
let info = this._prepareRequest(verb, requestUrl, headers);
|
|
153
|
+
let response = yield this._requestRaw(info, data);
|
|
154
|
+
let redirectsRemaining = this._maxRedirects;
|
|
155
|
+
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1
|
|
156
|
+
&& this._allowRedirects
|
|
157
|
+
&& redirectsRemaining > 0) {
|
|
158
|
+
const redirectUrl = response.message.headers["location"];
|
|
159
|
+
if (!redirectUrl) {
|
|
160
|
+
// if there's no location to redirect to, we won't
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
// we need to finish reading the response before reassigning response
|
|
164
|
+
// which will leak the open socket.
|
|
165
|
+
yield response.readBody();
|
|
166
|
+
// let's make the request with the new redirectUrl
|
|
167
|
+
info = this._prepareRequest(verb, redirectUrl, headers);
|
|
168
|
+
response = yield this._requestRaw(info, data);
|
|
169
|
+
redirectsRemaining--;
|
|
170
|
+
}
|
|
171
|
+
return response;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Needs to be called if keepAlive is set to true in request options.
|
|
176
|
+
*/
|
|
177
|
+
dispose() {
|
|
178
|
+
if (this._agent) {
|
|
179
|
+
this._agent.destroy();
|
|
180
|
+
}
|
|
181
|
+
this._disposed = true;
|
|
182
|
+
}
|
|
183
|
+
_requestRaw(info, data) {
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
let socket;
|
|
186
|
+
let isDataString = typeof (data) === 'string';
|
|
187
|
+
if (typeof (data) === 'string') {
|
|
188
|
+
info.options.headers["Content-Length"] = Buffer.byteLength(data, 'utf8');
|
|
189
|
+
}
|
|
190
|
+
let req = info.httpModule.request(info.options, (msg) => {
|
|
191
|
+
let res = new HttpClientResponse(msg);
|
|
192
|
+
resolve(res);
|
|
193
|
+
});
|
|
194
|
+
req.on('socket', (sock) => {
|
|
195
|
+
socket = sock;
|
|
196
|
+
});
|
|
197
|
+
// If we ever get disconnected, we want the socket to timeout eventually
|
|
198
|
+
req.setTimeout(this._socketTimeout || 3 * 60000, () => {
|
|
199
|
+
if (socket) {
|
|
200
|
+
socket.end();
|
|
201
|
+
}
|
|
202
|
+
reject(new Error('Request timeout: ' + info.options.path));
|
|
203
|
+
});
|
|
204
|
+
req.on('error', function (err) {
|
|
205
|
+
// err has statusCode property
|
|
206
|
+
// res should have headers
|
|
207
|
+
reject(err);
|
|
208
|
+
});
|
|
209
|
+
if (data && typeof (data) === 'string') {
|
|
210
|
+
req.write(data, 'utf8');
|
|
211
|
+
}
|
|
212
|
+
if (data && typeof (data) !== 'string') {
|
|
213
|
+
data.on('close', function () {
|
|
214
|
+
req.end();
|
|
215
|
+
});
|
|
216
|
+
data.pipe(req);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
req.end();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
_prepareRequest(method, requestUrl, headers) {
|
|
224
|
+
let info = {};
|
|
225
|
+
info.parsedUrl = url.parse(requestUrl);
|
|
226
|
+
let usingSsl = info.parsedUrl.protocol === 'https:';
|
|
227
|
+
info.httpModule = usingSsl ? https : http;
|
|
228
|
+
var defaultPort = usingSsl ? 443 : 80;
|
|
229
|
+
info.options = {};
|
|
230
|
+
info.options.host = info.parsedUrl.hostname;
|
|
231
|
+
info.options.port = info.parsedUrl.port ? parseInt(info.parsedUrl.port) : defaultPort;
|
|
232
|
+
info.options.path = (info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
|
|
233
|
+
info.options.method = method;
|
|
234
|
+
info.options.headers = headers || {};
|
|
235
|
+
info.options.headers["User-Agent"] = this.userAgent;
|
|
236
|
+
info.options.agent = this._getAgent(requestUrl);
|
|
237
|
+
// gives handlers an opportunity to participate
|
|
238
|
+
if (this.handlers) {
|
|
239
|
+
this.handlers.forEach((handler) => {
|
|
240
|
+
handler.prepareRequest(info.options);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return info;
|
|
244
|
+
}
|
|
245
|
+
_getAgent(requestUrl) {
|
|
246
|
+
let agent;
|
|
247
|
+
let proxy = this._getProxy(requestUrl);
|
|
248
|
+
let useProxy = proxy.proxyUrl && proxy.proxyUrl.hostname && !this._isBypassProxy(requestUrl);
|
|
249
|
+
if (this._keepAlive && useProxy) {
|
|
250
|
+
agent = this._proxyAgent;
|
|
251
|
+
}
|
|
252
|
+
if (this._keepAlive && !useProxy) {
|
|
253
|
+
agent = this._agent;
|
|
254
|
+
}
|
|
255
|
+
// if agent is already assigned use that agent.
|
|
256
|
+
if (!!agent) {
|
|
257
|
+
return agent;
|
|
258
|
+
}
|
|
259
|
+
var parsedUrl = url.parse(requestUrl);
|
|
260
|
+
let usingSsl = parsedUrl.protocol === 'https:';
|
|
261
|
+
let maxSockets = 100;
|
|
262
|
+
if (!!this.requestOptions) {
|
|
263
|
+
maxSockets = this.requestOptions.maxSockets || http.globalAgent.maxSockets;
|
|
264
|
+
}
|
|
265
|
+
if (useProxy) {
|
|
266
|
+
var agentOptions = {
|
|
267
|
+
maxSockets: maxSockets,
|
|
268
|
+
keepAlive: this._keepAlive,
|
|
269
|
+
proxy: {
|
|
270
|
+
proxyAuth: proxy.proxyAuth,
|
|
271
|
+
host: proxy.proxyUrl.hostname,
|
|
272
|
+
port: proxy.proxyUrl.port
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
var tunnelAgent;
|
|
276
|
+
var overHttps = proxy.proxyUrl.protocol === 'https:';
|
|
277
|
+
if (usingSsl) {
|
|
278
|
+
tunnelAgent = overHttps ? tunnel.httpsOverHttps : tunnel.httpsOverHttp;
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
tunnelAgent = overHttps ? tunnel.httpOverHttps : tunnel.httpOverHttp;
|
|
282
|
+
}
|
|
283
|
+
agent = tunnelAgent(agentOptions);
|
|
284
|
+
this._proxyAgent = agent;
|
|
285
|
+
}
|
|
286
|
+
// if reusing agent across request and tunneling agent isn't assigned create a new agent
|
|
287
|
+
if (this._keepAlive && !agent) {
|
|
288
|
+
var options = { keepAlive: this._keepAlive, maxSockets: maxSockets };
|
|
289
|
+
agent = usingSsl ? new https.Agent(options) : new http.Agent(options);
|
|
290
|
+
this._agent = agent;
|
|
291
|
+
}
|
|
292
|
+
// if not using private agent and tunnel agent isn't setup then use global agent
|
|
293
|
+
if (!agent) {
|
|
294
|
+
agent = usingSsl ? https.globalAgent : http.globalAgent;
|
|
295
|
+
}
|
|
296
|
+
if (usingSsl && this._ignoreSslError) {
|
|
297
|
+
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
|
298
|
+
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
|
299
|
+
// we have to cast it to any and change it directly
|
|
300
|
+
agent.options = Object.assign(agent.options || {}, { rejectUnauthorized: false });
|
|
301
|
+
}
|
|
302
|
+
if (usingSsl && this._certConfig) {
|
|
303
|
+
agent.options = Object.assign(agent.options || {}, { ca: this._ca, cert: this._cert, key: this._key, passphrase: this._certConfig.passphrase });
|
|
304
|
+
}
|
|
305
|
+
return agent;
|
|
306
|
+
}
|
|
307
|
+
_getProxy(requestUrl) {
|
|
308
|
+
var parsedUrl = url.parse(requestUrl);
|
|
309
|
+
let usingSsl = parsedUrl.protocol === 'https:';
|
|
310
|
+
let proxyConfig = this._httpProxy;
|
|
311
|
+
// fallback to http_proxy and https_proxy env
|
|
312
|
+
let https_proxy = process.env[EnvironmentVariables.HTTPS_PROXY];
|
|
313
|
+
let http_proxy = process.env[EnvironmentVariables.HTTP_PROXY];
|
|
314
|
+
if (!proxyConfig) {
|
|
315
|
+
if (https_proxy && usingSsl) {
|
|
316
|
+
proxyConfig = {
|
|
317
|
+
proxyUrl: https_proxy
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
else if (http_proxy) {
|
|
321
|
+
proxyConfig = {
|
|
322
|
+
proxyUrl: http_proxy
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
let proxyUrl;
|
|
327
|
+
let proxyAuth;
|
|
328
|
+
if (proxyConfig) {
|
|
329
|
+
if (proxyConfig.proxyUrl.length > 0) {
|
|
330
|
+
proxyUrl = url.parse(proxyConfig.proxyUrl);
|
|
331
|
+
}
|
|
332
|
+
if (proxyConfig.proxyUsername || proxyConfig.proxyPassword) {
|
|
333
|
+
proxyAuth = proxyConfig.proxyUsername + ":" + proxyConfig.proxyPassword;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return { proxyUrl: proxyUrl, proxyAuth: proxyAuth };
|
|
337
|
+
}
|
|
338
|
+
_isBypassProxy(requestUrl) {
|
|
339
|
+
if (!this._httpProxyBypassHosts) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
let bypass = false;
|
|
343
|
+
this._httpProxyBypassHosts.forEach(bypassHost => {
|
|
344
|
+
if (bypassHost.test(requestUrl)) {
|
|
345
|
+
bypass = true;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
return bypass;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
exports.HttpClient = HttpClient;
|