@e-mc/request 0.10.15 → 0.10.16

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/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.10.15/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.10.16/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -205,9 +205,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
205
205
 
206
206
  ## References
207
207
 
208
- - https://www.unpkg.com/@e-mc/types@0.10.15/lib/http.d.ts
209
- - https://www.unpkg.com/@e-mc/types@0.10.15/lib/request.d.ts
210
- - https://www.unpkg.com/@e-mc/types@0.10.15/lib/settings.d.ts
208
+ - https://www.unpkg.com/@e-mc/types@0.10.16/lib/http.d.ts
209
+ - https://www.unpkg.com/@e-mc/types@0.10.16/lib/request.d.ts
210
+ - https://www.unpkg.com/@e-mc/types@0.10.16/lib/settings.d.ts
211
211
 
212
212
  * https://www.npmjs.com/package/@types/node
213
213
 
package/index.js CHANGED
@@ -276,6 +276,8 @@ function checkEncoding(request, response, statusCode, outStream, contentEncoding
276
276
  case 206:
277
277
  request.emit('error', (0, types_1.errorValue)("Aborted", 'Partial content'));
278
278
  case 204:
279
+ case 205:
280
+ case 304:
279
281
  return;
280
282
  }
281
283
  if (!contentEncoding) {
@@ -375,6 +377,7 @@ function successDns(instance, value, pending, connected) {
375
377
  }
376
378
  pending.length = 0;
377
379
  }
380
+ const hasResponse = (value) => value >= 200 && (value < 300 || value === 304);
378
381
  const configureDns = (family, options) => family === 0 ? options : { family, hints: family === 6 ? dns.V4MAPPED : 0 };
379
382
  const ignoreOpt = (opts, ...values) => !opts?.some(item => values.includes(item));
380
383
  const escapeQuote = (value) => value.replace(/[\\"]/g, capture => '\\' + capture);
@@ -431,13 +434,21 @@ class Fetch {
431
434
  return;
432
435
  }
433
436
  const statusCode = headers[':status'];
434
- if (statusCode < 300) {
435
- this.acceptResponse(headers);
437
+ if (statusCode === 204 || statusCode === 304) {
438
+ this.acceptResponse(headers, true);
436
439
  }
437
- else if (statusCode < 400) {
440
+ else if (statusCode < 300) {
441
+ this.acceptResponse(headers, false);
442
+ }
443
+ else if (statusCode === 301 ||
444
+ statusCode === 302 ||
445
+ statusCode === 303 ||
446
+ statusCode === 307 ||
447
+ statusCode === 308) {
438
448
  this.redirectResponse(statusCode, headers.location);
439
449
  }
440
- else if (statusCode === 401 ||
450
+ else if (statusCode === 305 ||
451
+ statusCode === 401 ||
441
452
  statusCode === 402 ||
442
453
  statusCode === 403 ||
443
454
  statusCode === 404 ||
@@ -502,10 +513,17 @@ class Fetch {
502
513
  return;
503
514
  }
504
515
  const statusCode = res.statusCode;
505
- if (statusCode < 300) {
506
- this.acceptResponse(res.headers);
516
+ if (statusCode === 204 || statusCode === 304) {
517
+ this.acceptResponse(res.headers, true);
518
+ }
519
+ else if (statusCode < 300) {
520
+ this.acceptResponse(res.headers, false);
507
521
  }
508
- else if (statusCode < 400) {
522
+ else if (statusCode === 301 ||
523
+ statusCode === 302 ||
524
+ statusCode === 303 ||
525
+ statusCode === 307 ||
526
+ statusCode === 308) {
509
527
  this.redirectResponse(statusCode, res.headers.location);
510
528
  }
511
529
  else if (this.isRetry(statusCode)) {
@@ -586,7 +604,7 @@ class Fetch {
586
604
  this.opts.httpVersion = 1;
587
605
  this.init();
588
606
  }
589
- acceptResponse(headers) {
607
+ acceptResponse(headers, empty = false) {
590
608
  const { instance, config, client, opts, pipeTo } = this;
591
609
  const parent = this.instance.host;
592
610
  const progressId = config.progressId;
@@ -629,7 +647,7 @@ class Fetch {
629
647
  }
630
648
  });
631
649
  }
632
- if (enabled) {
650
+ if (enabled && !empty) {
633
651
  const encoding = opts.encoding;
634
652
  client.on('data', (chunk) => {
635
653
  if (buffer) {
@@ -726,7 +744,7 @@ class Fetch {
726
744
  if (contentLength > 0) {
727
745
  parent.updateProgress("request", progressId, 0, contentLength);
728
746
  }
729
- if (enabled && instance.readExpect === 'always') {
747
+ if (enabled && instance.readExpect === 'always' && !empty) {
730
748
  this.terminate("No data received");
731
749
  return;
732
750
  }
@@ -2102,7 +2120,7 @@ class Request extends module_1 {
2102
2120
  request.on('response', response => {
2103
2121
  connected = true;
2104
2122
  const statusCode = response[':status'];
2105
- if (this.matchStatus(statusCode, url, response, request, options) && statusCode >= 200 && statusCode < 300) {
2123
+ if (this.matchStatus(statusCode, url, response, request, options) && hasResponse(statusCode)) {
2106
2124
  if (emitter = checkEncoding(request, request, statusCode, outStream, response['content-encoding'])) {
2107
2125
  for (const event in listenerMap) {
2108
2126
  const [name, type] = event.split('-');
@@ -2224,7 +2242,7 @@ class Request extends module_1 {
2224
2242
  }, response => {
2225
2243
  const statusCode = response.statusCode;
2226
2244
  const incoming = response.headers;
2227
- if (this.matchStatus(statusCode, url, incoming, request, options) && (getting || posting) && statusCode >= 200 && statusCode < 300) {
2245
+ if (this.matchStatus(statusCode, url, incoming, request, options) && (getting || posting) && hasResponse(statusCode)) {
2228
2246
  let source = checkEncoding(request, response, statusCode, outStream, incoming['content-encoding']);
2229
2247
  if (source) {
2230
2248
  source.once('finish', () => request.emit('end'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.10.15",
3
+ "version": "0.10.16",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,11 +20,11 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.10.15",
24
- "@e-mc/types": "0.10.15",
23
+ "@e-mc/module": "0.10.16",
24
+ "@e-mc/types": "0.10.16",
25
25
  "combined-stream": "^1.0.8",
26
- "js-yaml": "^4.1.0",
27
- "picomatch": "^4.0.2",
26
+ "js-yaml": "^4.1.1",
27
+ "picomatch": "^4.0.3",
28
28
  "which": "^2.0.2"
29
29
  }
30
30
  }
@@ -1,569 +0,0 @@
1
- "use strict";
2
- const fs = require("node:fs");
3
- const http2 = require("node:http2");
4
- const yaml = require("js-yaml");
5
- const types_1 = require("@e-mc/types");
6
- const module_1 = require("@e-mc/module");
7
- const util_1 = require("@e-mc/request/util");
8
- const kHttpAdapter = Symbol.for('request:http:adapter:constructor');
9
- let LOG_TIMEFORMAT = 'readable';
10
- const isConstructor = (value) => typeof value === 'function' && !!value.prototype?.constructor.name;
11
- class HttpAdapter {
12
- instance;
13
- state;
14
- uri;
15
- static [kHttpAdapter] = true;
16
- static constructorOf(value) {
17
- return isConstructor(value) && value[kHttpAdapter] === true;
18
- }
19
- static isUnsupported(value) {
20
- return value === 421 || value === 505;
21
- }
22
- static isDowngrade(err) {
23
- return (0, types_1.isErrorCode)(err, 'ERR_HTTP2_ERROR') || err instanceof Error && this.isUnsupported(Math.abs(err.errno));
24
- }
25
- static wasAborted(err) {
26
- return err instanceof Error && err.message.startsWith("Aborted");
27
- }
28
- static isConnectionError(err) {
29
- return (0, types_1.isErrorCode)(err, 'ETIMEDOUT', 'ECONNRESET');
30
- }
31
- static defineHostConfig({ settings }) {
32
- const time_format = settings?.time_format;
33
- switch (time_format) {
34
- case 'readable':
35
- case 'relative':
36
- case 'none':
37
- LOG_TIMEFORMAT = time_format;
38
- break;
39
- }
40
- }
41
- contentLength = 0;
42
- retries = 0;
43
- redirects = 0;
44
- closed = false;
45
- aborted = false;
46
- timeout = null;
47
- dataTime = null;
48
- delayTime = undefined;
49
- opts;
50
- client;
51
- resolve;
52
- reject;
53
- startTime;
54
- #outStream = null;
55
- #options;
56
- constructor(instance, state, uri, options) {
57
- this.instance = instance;
58
- this.state = state;
59
- this.uri = uri;
60
- this.#options = options;
61
- this.startTime = state.log ? process.hrtime.bigint() : BigInt(0);
62
- this.setOpts();
63
- }
64
- async start() {
65
- return new Promise((resolve, reject) => {
66
- this.resolve = resolve;
67
- this.reject = reject;
68
- this.init();
69
- });
70
- }
71
- init() {
72
- this.aborted = false;
73
- this.setWriteStream();
74
- this.client = this.instance.open(this.uri, this.opts);
75
- if (this.opts.httpVersion === 2) {
76
- this.client
77
- .on('response', (headers, flags) => {
78
- if (this.destroyed) {
79
- return;
80
- }
81
- const statusCode = headers[':status'];
82
- if (statusCode < 300) {
83
- this.acceptResponse(headers);
84
- }
85
- else if (statusCode < 400) {
86
- this.redirectResponse(statusCode, headers.location);
87
- }
88
- else if (statusCode === 401 ||
89
- statusCode === 402 ||
90
- statusCode === 403 ||
91
- statusCode === 404 ||
92
- statusCode === 407 ||
93
- statusCode === 410) {
94
- this.terminate(this.formatStatus(statusCode));
95
- }
96
- else if (this.isRetry(statusCode)) {
97
- this.retryResponse(statusCode, headers['retry-after']);
98
- }
99
- else if (HttpAdapter.isUnsupported(statusCode)) {
100
- this.retryDownload(true, this.#formatNgFlags(http2.constants.NGHTTP2_PROTOCOL_ERROR, statusCode));
101
- }
102
- else {
103
- switch (flags) {
104
- case http2.constants.NGHTTP2_PROTOCOL_ERROR:
105
- case http2.constants.NGHTTP2_INADEQUATE_SECURITY:
106
- case http2.constants.NGHTTP2_HTTP_1_1_REQUIRED:
107
- this.retryDownload(true, this.#formatNgFlags(flags, statusCode, headers.location));
108
- break;
109
- default:
110
- this.retryDownload(false, this.formatStatus(statusCode));
111
- break;
112
- }
113
- }
114
- })
115
- .on('unknownProtocol', () => {
116
- if (this.aborted) {
117
- return;
118
- }
119
- this.retryDownload(true, 'Unknown protocol (HTTP/2)');
120
- })
121
- .on('aborted', () => {
122
- this.aborted = true;
123
- this.terminate((0, types_1.createAbortError)());
124
- })
125
- .on('error', async (err) => {
126
- if (this.aborted) {
127
- return;
128
- }
129
- if (HttpAdapter.wasAborted(err)) {
130
- this.errorResponse(err);
131
- }
132
- else {
133
- switch (!HttpAdapter.isDowngrade(err) && await this.host.hasProtocol(2)) {
134
- case 1:
135
- this.errorResponse(err);
136
- break;
137
- case 2:
138
- this.retryDownload(false, err);
139
- break;
140
- default:
141
- this.retryDownload(true, err);
142
- break;
143
- }
144
- }
145
- });
146
- }
147
- else {
148
- this.client
149
- .on('response', res => {
150
- if (this.destroyed) {
151
- return;
152
- }
153
- const statusCode = res.statusCode;
154
- if (statusCode < 300) {
155
- this.acceptResponse(res.headers);
156
- }
157
- else if (statusCode < 400) {
158
- this.redirectResponse(statusCode, res.headers.location);
159
- }
160
- else if (this.isRetry(statusCode)) {
161
- this.retryResponse(statusCode, res.headers['retry-after']);
162
- }
163
- else {
164
- this.terminate(this.formatStatus(statusCode));
165
- }
166
- })
167
- .on('abort', () => {
168
- this.aborted = true;
169
- this.terminate((0, types_1.createAbortError)());
170
- })
171
- .on('error', err => {
172
- if (this.aborted) {
173
- return;
174
- }
175
- this.errorResponse(err);
176
- });
177
- }
178
- this.client.on('timeout', () => {
179
- if (this.aborted) {
180
- return;
181
- }
182
- if (++this.retries <= this.retryLimit) {
183
- this.abortResponse();
184
- this.retryTimeout();
185
- }
186
- else {
187
- this.terminate(this.formatStatus(408));
188
- }
189
- });
190
- }
191
- setOpts(uri) {
192
- if (uri) {
193
- this.uri = uri;
194
- }
195
- this.opts = this.instance.opts(this.uri, this.#options);
196
- }
197
- setWriteStream() {
198
- const pipeTo = this.pipeTo;
199
- if (typeof pipeTo === 'string') {
200
- try {
201
- this.outStream = fs.createWriteStream(pipeTo, { emitClose: false, highWaterMark: this.host.streamSize });
202
- }
203
- catch (err) {
204
- this.terminate(err);
205
- }
206
- }
207
- else if (pipeTo) {
208
- this.outStream = pipeTo;
209
- }
210
- }
211
- retryDownload(downgrade, message) {
212
- if (this.aborted) {
213
- return;
214
- }
215
- this.abortResponse();
216
- if (downgrade) {
217
- const host = this.host;
218
- host.failed(2);
219
- if (host.version > 1) {
220
- if (this.state.verbose) {
221
- this.instance.formatMessage(1024, 'HTTP2', ["Unsupported protocol", host.origin], message, { failed: true });
222
- }
223
- host.version = 1;
224
- }
225
- }
226
- this.opts.httpVersion = 1;
227
- this.init();
228
- }
229
- acceptResponse(headers) {
230
- const opts = this.opts;
231
- if ('outHeaders' in opts) {
232
- opts.outHeaders = headers;
233
- }
234
- if ('outFilename' in opts) {
235
- opts.outFilename = (0, util_1.parseHeader)(headers, 'content-disposition');
236
- }
237
- const pipeline = this.pipeTo ? !(0, types_1.isString)(this.pipeTo) : false;
238
- const enabled = opts.connected?.call(this.client, headers) !== false && !pipeline;
239
- const maxBufferSize = opts.maxBufferSize ? (0, types_1.alignSize)(opts.maxBufferSize) : 0;
240
- this.contentLength = parseInt(headers['content-length'] || '0');
241
- const updating = opts.progressId !== undefined && !!this.instance.host && this.contentLength > 0;
242
- const readTimeout = this.instance.readTimeout;
243
- let log = this.state.log, buffer = null, dataLength = 0;
244
- this.client.once('readable', () => {
245
- if (readTimeout > 0) {
246
- this.timeout = setTimeout(() => {
247
- this.terminate((0, types_1.errorValue)("Timeout was exceeded", this.uri.toString()));
248
- }, readTimeout);
249
- }
250
- if (log) {
251
- switch (this.instance.settings?.time_format || LOG_TIMEFORMAT) {
252
- case 'readable':
253
- this.delayTime = process.hrtime.bigint() - this.startTime;
254
- break;
255
- case 'relative':
256
- this.delayTime = Date.now() - this.instance.startTime;
257
- break;
258
- case 'none':
259
- if (!this.silent) {
260
- log = false;
261
- }
262
- break;
263
- }
264
- }
265
- this.dataTime = process.hrtime.bigint();
266
- if (updating) {
267
- this.updateProgress(0, 0);
268
- }
269
- });
270
- if (enabled) {
271
- const encoding = opts.encoding;
272
- this.client.on('data', (chunk) => {
273
- if (buffer) {
274
- if (typeof buffer === 'string') {
275
- buffer += typeof chunk === 'string' ? chunk : chunk.toString(encoding);
276
- }
277
- else if (Array.isArray(buffer)) {
278
- buffer.push(typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk);
279
- }
280
- else {
281
- buffer = Buffer.concat([buffer, typeof chunk === 'string' ? Buffer.from(chunk, encoding) : chunk]);
282
- }
283
- }
284
- else {
285
- buffer = typeof chunk === 'string' ? chunk : [chunk];
286
- }
287
- if (updating) {
288
- dataLength += Buffer.byteLength(chunk, encoding);
289
- this.updateProgress(dataLength, this.contentLength);
290
- }
291
- if (maxBufferSize > 0) {
292
- if (!updating) {
293
- dataLength += Buffer.byteLength(chunk, encoding);
294
- }
295
- if (dataLength > maxBufferSize) {
296
- this.terminate((0, types_1.errorValue)("Size limit was exceeded", this.uri.toString()));
297
- }
298
- }
299
- });
300
- }
301
- if (opts.trailers) {
302
- this.client.once('trailers', (trailers) => {
303
- opts.trailers.call(this.client, trailers);
304
- });
305
- }
306
- this.client.once('end', () => {
307
- if (this.closed || this.aborted) {
308
- return;
309
- }
310
- this.close();
311
- const encoding = opts.encoding;
312
- let result;
313
- if (buffer) {
314
- if (Array.isArray(buffer)) {
315
- buffer = Buffer.concat(buffer);
316
- if (encoding) {
317
- buffer = buffer.toString(encoding);
318
- }
319
- }
320
- dataLength = Buffer.byteLength(buffer, encoding);
321
- if (updating) {
322
- this.updateProgress(dataLength, dataLength);
323
- }
324
- if (typeof buffer === 'string') {
325
- if (buffer.startsWith('\uFEFF') && encoding !== 'utf16le' && encoding !== 'utf-16le') {
326
- buffer = buffer.substring(1);
327
- }
328
- if (opts.outFormat) {
329
- const { out: format, parser } = opts.outFormat;
330
- let packageName;
331
- try {
332
- switch (format) {
333
- case 'yaml':
334
- result = yaml.load(buffer, parser);
335
- break;
336
- case 'json5':
337
- result = require(packageName = 'json5').parse(buffer);
338
- break;
339
- case 'xml':
340
- result = new (require(packageName = 'fast-xml-parser').XMLParser)(parser).parse(buffer);
341
- break;
342
- case 'toml':
343
- result = require(packageName = 'toml').parse(buffer);
344
- break;
345
- default:
346
- result = JSON.parse(buffer);
347
- break;
348
- }
349
- if (!(0, types_1.isObject)(result)) {
350
- result = null;
351
- }
352
- }
353
- catch (err) {
354
- if (this.state.verbose && !(packageName && this.instance.checkPackage(err, packageName))) {
355
- this.instance.writeFail(["Unable to parse URI response", format], err, 1024);
356
- }
357
- result = null;
358
- }
359
- }
360
- }
361
- if (result === undefined) {
362
- result = buffer;
363
- }
364
- }
365
- else {
366
- if (updating) {
367
- this.updateProgress(0, this.contentLength);
368
- }
369
- if (enabled && this.instance.readExpect === 'always') {
370
- this.terminate("No data received");
371
- return;
372
- }
373
- dataLength = this.contentLength || (typeof this.pipeTo === 'string' ? (0, util_1.getSize)(this.pipeTo) : 0);
374
- result = encoding && !pipeline ? '' : null;
375
- }
376
- this.endResponse(result, dataLength, log);
377
- });
378
- this.host.success(this.httpVersion);
379
- }
380
- updateProgress(dataLength, contentLength) {
381
- const { host, moduleName } = this.instance;
382
- host.updateProgress(moduleName, this.opts.progressId, dataLength, contentLength, this.dataTime);
383
- }
384
- endResponse(result, dataLength = 0, logging = this.state.log) {
385
- if (logging) {
386
- this.instance.writeTimeProcess('HTTP' + this.httpVersion, this.opts.statusMessage || this.uri.toString(), this.startTime, {
387
- type: 1024,
388
- queue: !!this.instance.host,
389
- titleBgColor: !result ? 'bgBlue' : undefined,
390
- messageUnit: this.formatMibs(dataLength),
391
- messageUnitMinWidth: 9,
392
- delayTime: this.delayTime,
393
- bypassLog: module_1.hasLogType(32768)
394
- });
395
- }
396
- this.resolve(result);
397
- }
398
- redirectResponse(statusCode, location) {
399
- if (location) {
400
- if (this.opts.followRedirect === false) {
401
- this.terminate(this.formatStatus(statusCode, "Follow redirect was disabled"));
402
- }
403
- else if (++this.redirects <= this.redirectLimit) {
404
- this.abortResponse();
405
- this.setOpts((0, util_1.fromURL)(this.opts.url, location));
406
- this.init();
407
- }
408
- else {
409
- this.terminate(this.formatStatus(statusCode, "Exceeded redirect limit"));
410
- }
411
- }
412
- else {
413
- this.terminate(this.formatStatus(statusCode, "Missing redirect location"));
414
- }
415
- }
416
- abortResponse() {
417
- if (this.closed) {
418
- return;
419
- }
420
- this.aborted = true;
421
- this.client.destroy();
422
- this.instance.reset(this);
423
- this.cleanup();
424
- }
425
- errorResponse(err) {
426
- if (HttpAdapter.wasAborted(err)) {
427
- this.terminate(err);
428
- }
429
- else if ((0, util_1.checkRetryable)(err) && ++this.retries <= this.retryLimit) {
430
- this.abortResponse();
431
- if (HttpAdapter.isConnectionError(err)) {
432
- this.retryTimeout();
433
- }
434
- else {
435
- setTimeout(() => {
436
- this.init();
437
- }, this.retryWait);
438
- }
439
- }
440
- else {
441
- this.host.error(this.httpVersion);
442
- this.terminate(err);
443
- }
444
- }
445
- retryResponse(statusCode, retryAfter) {
446
- this.abortResponse();
447
- if (retryAfter && this.retryAfter > 0) {
448
- let offset = +retryAfter || new Date(retryAfter);
449
- if (offset instanceof Date) {
450
- offset = Math.max(0, offset.getTime() - Date.now());
451
- }
452
- else {
453
- offset *= 1000;
454
- }
455
- if (offset > 0) {
456
- if (offset <= this.retryAfter) {
457
- this.sendWarning(`Retry After (${retryAfter})`);
458
- setTimeout(() => {
459
- this.init();
460
- }, offset);
461
- }
462
- else {
463
- this.terminate(this.formatStatus(statusCode));
464
- }
465
- return;
466
- }
467
- }
468
- this.sendWarning(this.#formatRetry((0, util_1.fromStatusCode)(statusCode)));
469
- if ((0, util_1.isRetryable)(statusCode, true)) {
470
- setImmediate(this.init.bind(this));
471
- }
472
- else {
473
- setTimeout(() => {
474
- this.init();
475
- }, this.retryWait);
476
- }
477
- }
478
- isRetry(value) {
479
- return (0, util_1.isRetryable)(value) && ++this.retries <= this.retryLimit;
480
- }
481
- retryTimeout() {
482
- this.sendWarning(this.#formatRetry("HTTP connection timeout"));
483
- this.init();
484
- }
485
- terminate(err) {
486
- if (this.closed) {
487
- return;
488
- }
489
- this.cleanup();
490
- this.close();
491
- this.reject(typeof err === 'string' ? new Error(err) : err);
492
- }
493
- sendWarning(message) {
494
- if (this.state.verbose) {
495
- const { host, url } = this.opts;
496
- this.instance.formatMessage(1024, 'HTTP' + this.httpVersion, [message, host.origin], url.toString(), { ...module_1.LOG_STYLE_WARN });
497
- }
498
- }
499
- formatStatus(value, hint) {
500
- return value + ': ' + (hint || (0, util_1.fromStatusCode)(value)) + ` (${this.uri.toString()})`;
501
- }
502
- formatMibs(dataLength) {
503
- if (dataLength > 0 && this.dataTime) {
504
- return (0, util_1.getTransferRate)(dataLength, Math.max(1, (0, types_1.convertTime)(process.hrtime.bigint() - this.dataTime, false) * 1000));
505
- }
506
- }
507
- close() {
508
- this.closed = true;
509
- this.instance.reset(this);
510
- if (this.aborted && !this.client.aborted) {
511
- this.abortController?.abort();
512
- }
513
- }
514
- cleanup() {
515
- if ((0, types_1.isString)(this.pipeTo) && this.outStream) {
516
- (0, util_1.cleanupStream)(this.outStream, this.pipeTo);
517
- this.outStream = null;
518
- }
519
- }
520
- #formatNgFlags(value, statusCode, location) {
521
- return location ? `Using HTTP 1.1 for URL redirect (${location})` : this.formatStatus(statusCode, value ? 'NGHTTP2 Error ' + value : '');
522
- }
523
- #formatRetry(message) {
524
- return `${message} (${this.retries} / ${this.retryLimit})`;
525
- }
526
- set abortController(value) {
527
- this.opts.outAbort = value;
528
- }
529
- get abortController() {
530
- return this.opts.outAbort || null;
531
- }
532
- set outStream(value) {
533
- this.#outStream = value;
534
- if (value) {
535
- this.opts.outStream = value;
536
- }
537
- }
538
- get outStream() {
539
- return this.#outStream;
540
- }
541
- get destroyed() {
542
- return this.client.destroyed || this.httpVersion === 2 && this.client.aborted;
543
- }
544
- get host() {
545
- return this.opts.host;
546
- }
547
- get httpVersion() {
548
- return this.opts.httpVersion;
549
- }
550
- get pipeTo() {
551
- return this.opts.pipeTo;
552
- }
553
- get silent() {
554
- return this.opts.silent === false;
555
- }
556
- get retryLimit() {
557
- return this.state.config.retryLimit;
558
- }
559
- get retryWait() {
560
- return this.state.config.retryWait;
561
- }
562
- get retryAfter() {
563
- return this.state.config.retryAfter;
564
- }
565
- get redirectLimit() {
566
- return this.state.config.redirectLimit;
567
- }
568
- }
569
- module.exports = HttpAdapter;