undici
Advanced tools
Comparing version 6.9.0 to 6.10.0
@@ -38,2 +38,8 @@ # Class: RetryHandler | ||
**`RetryState`** | ||
It represents the retry state for a given request. | ||
- `counter`: `number` - Current retry attempt. | ||
### Parameter `RetryHandlers` | ||
@@ -40,0 +46,0 @@ |
@@ -0,1 +1,2 @@ | ||
'use strict' | ||
const assert = require('node:assert') | ||
@@ -40,3 +41,3 @@ | ||
maxTimeout: maxTimeout ?? 30 * 1000, // 30s, | ||
timeout: minTimeout ?? 500, // .5s | ||
minTimeout: minTimeout ?? 500, // .5s | ||
timeoutFactor: timeoutFactor ?? 2, | ||
@@ -63,2 +64,3 @@ maxRetries: maxRetries ?? 5, | ||
this.retryCount = 0 | ||
this.retryCountCheckpoint = 0 | ||
this.start = 0 | ||
@@ -109,3 +111,3 @@ this.end = null | ||
maxRetries, | ||
timeout, | ||
minTimeout, | ||
maxTimeout, | ||
@@ -117,7 +119,4 @@ timeoutFactor, | ||
} = retryOptions | ||
let { counter, currentTimeout } = state | ||
const { counter } = state | ||
currentTimeout = | ||
currentTimeout != null && currentTimeout > 0 ? currentTimeout : timeout | ||
// Any code that is not a Undici's originated and allowed to retry | ||
@@ -166,6 +165,4 @@ if ( | ||
? Math.min(retryAfterHeader, maxTimeout) | ||
: Math.min(currentTimeout * timeoutFactor ** counter, maxTimeout) | ||
: Math.min(minTimeout * timeoutFactor ** (counter - 1), maxTimeout) | ||
state.currentTimeout = retryTimeout | ||
setTimeout(() => cb(null), retryTimeout) | ||
@@ -317,6 +314,15 @@ } | ||
// We reconcile in case of a mix between network errors | ||
// and server error response | ||
if (this.retryCount - this.retryCountCheckpoint > 0) { | ||
// We count the difference between the last checkpoint and the current retry count | ||
this.retryCount = this.retryCountCheckpoint + (this.retryCount - this.retryCountCheckpoint) | ||
} else { | ||
this.retryCount += 1 | ||
} | ||
this.retryOpts.retry( | ||
err, | ||
{ | ||
state: { counter: this.retryCount++, currentTimeout: this.retryAfter }, | ||
state: { counter: this.retryCount }, | ||
opts: { retryOptions: this.retryOpts, ...this.opts } | ||
@@ -343,2 +349,3 @@ }, | ||
try { | ||
this.retryCountCheckpoint = this.retryCount | ||
this.dispatch(this.opts, this) | ||
@@ -345,0 +352,0 @@ } catch (err) { |
@@ -160,8 +160,23 @@ 'use strict' | ||
[nodeUtil.inspect.custom] (depth, options) { | ||
let output = 'FormData:\n' | ||
this[kState].forEach(entry => { | ||
output += `${entry.name}: ${entry.value}\n` | ||
}) | ||
const state = this[kState].reduce((a, b) => { | ||
if (a[b.name]) { | ||
if (Array.isArray(a[b.name])) { | ||
a[b.name].push(b.value) | ||
} else { | ||
a[b.name] = [a[b.name], b.value] | ||
} | ||
} else { | ||
a[b.name] = b.value | ||
} | ||
return output | ||
return a | ||
}, { __proto__: null }) | ||
options.depth ??= depth | ||
options.colors ??= true | ||
const output = nodeUtil.formatWithOptions(options, state) | ||
// remove [Object null prototype] | ||
return `FormData ${output.slice(output.indexOf(']') + 2)}` | ||
} | ||
@@ -168,0 +183,0 @@ } |
@@ -575,12 +575,6 @@ // https://github.com/Ethan-Arrowood/undici-fetch | ||
[Symbol.for('nodejs.util.inspect.custom')] () { | ||
webidl.brandCheck(this, Headers) | ||
return this[kHeadersList] | ||
} | ||
[util.inspect.custom] (depth, options) { | ||
const inspected = util.inspect(this[kHeadersList].entries) | ||
options.depth ??= depth | ||
return `Headers ${inspected}` | ||
return `Headers ${util.formatWithOptions(options, this[kHeadersList].entries)}` | ||
} | ||
@@ -587,0 +581,0 @@ } |
@@ -781,2 +781,4 @@ /* globals AbortController */ | ||
options.colors ??= true | ||
const properties = { | ||
@@ -800,3 +802,3 @@ method: this.method, | ||
return nodeUtil.formatWithOptions(options, { ...properties }) | ||
return `Request ${nodeUtil.formatWithOptions(options, properties)}` | ||
} | ||
@@ -803,0 +805,0 @@ } |
@@ -262,2 +262,4 @@ 'use strict' | ||
options.colors ??= true | ||
const properties = { | ||
@@ -275,3 +277,3 @@ status: this.status, | ||
return nodeUtil.formatWithOptions(options, `Response ${nodeUtil.inspect(properties)}`) | ||
return `Response ${nodeUtil.formatWithOptions(options, properties)}` | ||
} | ||
@@ -278,0 +280,0 @@ } |
{ | ||
"name": "undici", | ||
"version": "6.9.0", | ||
"version": "6.10.0", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "https://undici.nodejs.org", |
@@ -21,2 +21,5 @@ import { URL } from 'url' | ||
connect(options: Dispatcher.ConnectOptions, callback: (err: Error | null, data: Dispatcher.ConnectData) => void): void; | ||
/** Compose a chain of dispatchers */ | ||
compose(dispatchers: Dispatcher['dispatch'][]): Dispatcher.ComposedDispatcher; | ||
compose(...dispatchers: Dispatcher['dispatch'][]): Dispatcher.ComposedDispatcher; | ||
/** Performs an HTTP request. */ | ||
@@ -97,2 +100,4 @@ request(options: Dispatcher.RequestOptions): Promise<Dispatcher.ResponseData>; | ||
declare namespace Dispatcher { | ||
export interface ComposedDispatcher extends Dispatcher {} | ||
export type DispatcherInterceptor = (dispatch: Dispatcher['dispatch']) => Dispatcher['dispatch']; | ||
export interface DispatchOptions { | ||
@@ -99,0 +104,0 @@ origin?: string | URL; |
@@ -15,3 +15,3 @@ import Dispatcher from "./dispatcher"; | ||
declare namespace RetryHandler { | ||
export type RetryState = { counter: number; currentTimeout: number }; | ||
export type RetryState = { counter: number; }; | ||
@@ -18,0 +18,0 @@ export type RetryContext = { |
1126214
23421
8