Foundation.Retry.HTTP (foundation v0.2.1)

Copy Markdown View Source

HTTP retry helpers with generic status, method, and Retry-After parsing helpers.

Provides retry delay calculation, status classification, and Retry-After parsing.

Summary

Functions

Parse Retry-After headers into milliseconds.

Calculate the retry delay for the given attempt.

Calculate the retry delay with custom initial and max delays.

Determine whether a status code is retryable.

Determine whether a status code is retryable for the given method under caller-provided method rules.

Decide whether a response should be retried based on headers and status.

Decide whether a response should be retried based on the given method, headers, and caller-provided method rules.

Types

headers()

@type headers() :: [{String.t(), String.t()}] | map()

method()

@type method() :: atom() | String.t()

retryable_statuses_by_method()

@type retryable_statuses_by_method() ::
  keyword([integer()]) | %{optional(method() | :all) => [integer()]}

Functions

parse_retry_after(headers, default_ms \\ 1000)

@spec parse_retry_after(headers(), non_neg_integer()) :: non_neg_integer()

Parse Retry-After headers into milliseconds.

Supports:

  • retry-after-ms - milliseconds
  • retry-after - delta-seconds
  • retry-after - HTTP-date

retry_delay(attempt)

@spec retry_delay(non_neg_integer()) :: non_neg_integer()

Calculate the retry delay for the given attempt.

retry_delay(attempt, initial_delay_ms, max_delay_ms)

@spec retry_delay(non_neg_integer(), pos_integer(), pos_integer()) ::
  non_neg_integer()

Calculate the retry delay with custom initial and max delays.

retryable_status?(status)

@spec retryable_status?(integer()) :: boolean()

Determine whether a status code is retryable.

retryable_status_for_method?(status, method, rules)

@spec retryable_status_for_method?(
  integer(),
  method(),
  retryable_statuses_by_method()
) :: boolean()

Determine whether a status code is retryable for the given method under caller-provided method rules.

Rules may be provided as a map or keyword list keyed by HTTP method or :all.

should_retry?(response)

@spec should_retry?(map() | {integer(), headers()} | integer()) :: boolean()

Decide whether a response should be retried based on headers and status.

should_retry_for_method?(method, response, rules)

@spec should_retry_for_method?(
  method(),
  map() | {integer(), headers()} | integer(),
  retryable_statuses_by_method()
) :: boolean()

Decide whether a response should be retried based on the given method, headers, and caller-provided method rules.