Crates.io | date_header |
lib.rs | date_header |
version | 1.0.5 |
source | src |
created_at | 2023-08-14 03:50:55.12521 |
updated_at | 2023-08-14 04:27:46.423255 |
description | Parsing and formatting for the HTTP Date: header |
homepage | |
repository | https://github.com/jayshua/date_header |
max_upload_size | |
id | 943836 |
size | 37,866 |
Multiple HTTP header fields store timestamps.
For example, a response created on May 15, 2015 may contain the header
Date: Fri, 15 May 2015 15:34:21 GMT
. Since the timestamp does not
contain any timezone or leap second information, it is equivalent to
writing 1431696861 Unix time.
This crate provides two functions:
parse
to parse an HTTP datetime string to a u64 unix timestamp
format
to format a u64 unix timestamp to an IMF-fixdate
let header = b"Fri, 15 May 2015 15:34:21 GMT";
assert_eq!(Ok(1431704061), date_header::parse(header));
let mut header = [0u8; 29];
assert_eq!(Ok(()), date_header::format(1431704061, &mut header));
assert_eq!(&header, b"Fri, 15 May 2015 15:34:21 GMT");
The date header is technically supposed to contain an IMF-fixdate value, but three formats actually exist in the wild. This crate attempts parsing all three when calling parse.
This is a fork of https://github.com/pyfisch/httpdate to fix some things that I found mildly annoying while using it.
Changes include:
Here's a link to pyfisch's blog post on the original crate: https://pyfisch.org/blog/http-datetime-handling/