Skip to content

Clamp out-of-range SystemTime instead of panicking in date headers#232

Open
SAY-5 wants to merge 1 commit into
hyperium:masterfrom
SAY-5:fix-httpdate-out-of-range-panic
Open

Clamp out-of-range SystemTime instead of panicking in date headers#232
SAY-5 wants to merge 1 commit into
hyperium:masterfrom
SAY-5:fix-httpdate-out-of-range-panic

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jul 26, 2026

Copy link
Copy Markdown

Fixes #230.

From<SystemTime> for HttpDate is where every date header conversion (Date, LastModified, Expires, IfModifiedSince, IfUnmodifiedSince, RetryAfter::date, IfRange::date, and is_modified) ends up, and httpdate panics there on a SystemTime before the Unix epoch or past year 9999. A pre-1970 file mtime handed to LastModified::from(metadata.modified()?) aborts the request handler even though the signature accepts any SystemTime.

This clamps the value to the representable range before the conversion so those calls return a date instead of panicking. Happy to switch to documenting the panic instead if you would rather keep the current behavior.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

From<SystemTime> for HttpDate panics on times before 1970 or after year 9999

1 participant