(opts, handlers)
| 9303 | // |
| 9304 | var require_retry_handler = __commonJS({ |
| 9305 | ""(exports, module) { |
| 9306 | "use strict"; |
| 9307 | var assert = __require("assert"); |
| 9308 | var { kRetryHandlerDefaultRetry } = require_symbols(); |
| 9309 | var { RequestRetryError } = require_errors(); |
| 9310 | var { |
| 9311 | isDisturbed, |
| 9312 | parseHeaders, |
| 9313 | parseRangeHeader, |
| 9314 | wrapRequestBody |
| 9315 | } = require_util(); |
| 9316 | function calculateRetryAfterHeader(retryAfter) { |
| 9317 | const current = Date.now(); |
| 9318 | return new Date(retryAfter).getTime() - current; |
| 9319 | } |
| 9320 | function validatePartialResponseContentLength(headers, range, statusCode, retryCount) { |
| 9321 | const contentLength = headers["content-length"]; |
| 9322 | if (contentLength == null) { |
| 9323 | return null; |
| 9324 | } |
| 9325 | if (!Number.isFinite(range.start) || !Number.isFinite(range.end)) { |
| 9326 | return null; |
| 9327 | } |
| 9328 | const length = Number(contentLength); |
| 9329 | const expectedLength = range.end - range.start + 1; |
| 9330 | if (!Number.isFinite(length) || length !== expectedLength) { |
| 9331 | return new RequestRetryError("Content-Length mismatch", statusCode, { |
| 9332 | headers, |
| 9333 | data: { count: retryCount } |
| 9334 | }); |
| 9335 | } |
| 9336 | return null; |
| 9337 | } |
| 9338 | var RetryHandler = class _RetryHandler { |
| 9339 | constructor(opts, handlers) { |
| 9340 | const _a = opts, { retryOptions } = _a, dispatchOpts = __objRest(_a, ["retryOptions"]); |
| 9341 | const { |
| 9342 | // Retry scoped |
| 9343 | retry: retryFn, |
| 9344 | maxRetries, |
| 9345 | maxTimeout, |
| 9346 | minTimeout, |
| 9347 | timeoutFactor, |
| 9348 | // Response scoped |
| 9349 | methods, |
| 9350 | errorCodes, |
| 9351 | retryAfter, |
| 9352 | statusCodes |
| 9353 | } = retryOptions != null ? retryOptions : {}; |
| 9354 | this.dispatch = handlers.dispatch; |
| 9355 | this.handler = handlers.handler; |
| 9356 | this.opts = __spreadProps(__spreadValues({}, dispatchOpts), { body: wrapRequestBody(opts.body) }); |
| 9357 | this.abort = null; |
| 9358 | this.aborted = false; |
| 9359 | this.retryOpts = { |
| 9360 | retry: retryFn != null ? retryFn : _RetryHandler[kRetryHandlerDefaultRetry], |
| 9361 | retryAfter: retryAfter != null ? retryAfter : true, |
| 9362 | maxTimeout: maxTimeout != null ? maxTimeout : 30 * 1e3, |
nothing calls this directly
no test coverage detected