12345678910111213141516171819202122232425262728293031(* Strict numeric parse for machine headers: trims surrounding whitespace,
rejects NaN/infinity (which [float_of_string_opt] would otherwise accept),
and rejects negative values. Returns the parsed non-negative finite float. *)letparse_non_negative_secondsvalue=matchfloat_of_string_opt(String.trimvalue)with|SomefwhenFloat.is_finitef&&f>=0.0->Somef|Some_|None->None(* retry-after-ms is milliseconds. A present, numeric value wins outright:
upstream sets [ms] from it and never falls through to retry-after, so a
negative or infinite millisecond value resolves to [None] overall rather than
deferring to retry-after. A missing, non-numeric, or NaN value falls through
(upstream's [parseFloat] yields NaN for non-numeric input, which its
[!isNaN] guard treats the same as absent). *)letof_retry_after_msvalue=matchfloat_of_string_opt(String.trimvalue)with|SomemswhenFloat.is_nanms->`Fall_through|SomemswhenFloat.is_finitems&&ms>=0.0->`Seconds(ms/.1000.0)|Some_->`Rejected|None->`Fall_throughletparse~retry_after_ms~retry_after=letfrom_ms=matchretry_after_mswith|Somevalue->of_retry_after_msvalue|None->`Fall_throughinmatchfrom_mswith|`Secondss->Somes|`Rejected->None|`Fall_through->Option.bindretry_afterparse_non_negative_seconds