Expand description
Django-shape HTTP date parser + formatter — RFC 1123 / RFC 850 /
ANSI C asctime parsing per RFC 7231 §7.1.1.1; IMF-fixdate output
per RFC 1123. http_date::http_date(secs) + parse_http_date(s).
Django-shape HTTP date parser + formatter.
Mirrors django.utils.http.{http_date, parse_http_date} — used
for Last-Modified, If-Modified-Since, If-Unmodified-Since,
Expires, Date and similar HTTP date headers.
Per RFC 7231 §7.1.1.1, an HTTP server must EMIT IMF-fixdate (the RFC 1123 form) but must ACCEPT all three historical formats:
- IMF-fixdate (RFC 1123, modern preferred):
"Sun, 06 Nov 1994 08:49:37 GMT" - RFC 850 (obsolete, two-digit year, hyphenated date,
weekday spelled out):
"Sunday, 06-Nov-94 08:49:37 GMT" - ANSI C asctime() (no zone, no comma):
"Sun Nov 6 08:49:37 1994"
ⓘ
use rustango::http_date::{http_date, parse_http_date};
// Format current epoch seconds as IMF-fixdate.
let header = http_date(0);
assert_eq!(header, "Thu, 01 Jan 1970 00:00:00 GMT");
// Parse all three legacy shapes.
assert_eq!(parse_http_date("Sun, 06 Nov 1994 08:49:37 GMT"), Some(784111777));
assert_eq!(parse_http_date("Sunday, 06-Nov-94 08:49:37 GMT"), Some(784111777));
assert_eq!(parse_http_date("Sun Nov 6 08:49:37 1994"), Some(784111777));Functions§
- http_
date - Format a Unix timestamp (seconds since epoch) as an IMF-fixdate
HTTP date header —
"Sun, 06 Nov 1994 08:49:37 GMT". Django’shttp_date(epoch_seconds). - parse_
http_ date - Parse any of the three RFC 7231 §7.1.1.1 HTTP date shapes
(RFC 1123 IMF-fixdate, RFC 850, ANSI C asctime) into Unix epoch
seconds. Django’s
parse_http_date(s).