Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-httpclient

Named HTTP clients for Pudu: a client factory, delegating handlers, pooled keep-alive connections, handler lifetimes, logging, and resilience

0.1.1Apache-2.01

InstallClose

RetryAfter.pudu

Pudu20 lines704 B

GitHub ↗
1/** @Domain.RetryAfter.Module — how long a server asked the client to wait */2module PuduLangHttpClient.Domain.RetryAfter34import Std.Math as Math5import PuduLangHttpClient.Domain.Date as Date67/// The wait a `retry-after` value asks for in milliseconds at `now` milliseconds since the Unix8/// epoch: a count of seconds, or the time until an HTTP date, never below zero; `None` when the9/// value is neither.10export fn delay(value: Str, now: Int) -> Option[Int] {11  let trimmed = value.trim()12  match trimmed.toInt() {13    case Some(seconds) => if seconds < 0 { None } else { Some(seconds * 1000) }14    case None => {15      let at = Date.parse(trimmed) ?16      Some(Math.max(at - now, 0))17    }18  }19}20