https://github.com/pyfisch/httpdate
HTTP date parsing and formatting
https://github.com/pyfisch/httpdate
Last synced: 3 months ago
JSON representation
HTTP date parsing and formatting
- Host: GitHub
- URL: https://github.com/pyfisch/httpdate
- Owner: pyfisch
- License: apache-2.0
- Created: 2016-10-02T20:32:05.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-12-22T13:34:22.000Z (over 1 year ago)
- Last Synced: 2026-03-08T20:46:40.053Z (3 months ago)
- Language: Rust
- Size: 39.1 KB
- Stars: 58
- Watchers: 2
- Forks: 16
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# Date and time utils for HTTP.
[](https://github.com/pyfisch/httpdate/actions/workflows/ci.yml)
[](https://crates.io/crates/httpdate)
[](https://docs.rs/httpdate)
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 equvivalent to
writing 1431696861 Unix time. Rust’s `SystemTime` is used to store
these timestamps.
This crate provides two public functions:
* `parse_http_date` to parse a HTTP datetime string to a system time
* `fmt_http_date` to format a system time to a IMF-fixdate
In addition it exposes the `HttpDate` type that can be used to parse
and format timestamps. Convert a sytem time to `HttpDate` and vice versa.
The `HttpDate` (8 bytes) is smaller than `SystemTime` (16 bytes) and
using the display impl avoids a temporary allocation.
Read the [blog post](https://pyfisch.org/blog/http-datetime-handling/) to learn
more.
Fuzz it by installing *cargo-fuzz* and running `cargo fuzz run fuzz_target_1`.