use std::fmt; use std::str::FromStr; use std::time::SystemTime;
use bytes::Bytes; use http::header::HeaderValue; use httpdate;
usesuper::IterExt;
/// A timestamp with HTTP formatting and parsing // Prior to 1995, there were three different formats commonly used by // servers to communicate timestamps. For compatibility with old // implementations, all three are defined here. The preferred format is // a fixed-length and single-zone subset of the date and time // specification used by the Internet Message Format [RFC5322]. // // HTTP-date = IMF-fixdate / obs-date // // An example of the preferred format is // // Sun, 06 Nov 1994 08:49:37 GMT ; IMF-fixdate // // Examples of the two obsolete formats are // // Sunday, 06-Nov-94 08:49:37 GMT ; obsolete RFC 850 format // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format // // A recipient that parses a timestamp value in an HTTP header field // MUST accept all three HTTP-date formats. When a sender generates a // header field that contains one or more timestamps defined as // HTTP-date, the sender MUST generate those timestamps in the // IMF-fixdate format. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub(crate) struct HttpDate(httpdate::HttpDate);
impl<'a> From<&'a HttpDate> for HeaderValue { fn from(date: &'a HttpDate) -> HeaderValue { // TODO: could be just BytesMut instead of String let s = date.to_string(); let bytes = Bytes::from(s);
HeaderValue::from_maybe_shared(bytes).expect("HttpDate always is a valid value")
}
}
impl FromStr for HttpDate { type Err = Error; fn from_str(s: &str) -> Result<HttpDate, Error> {
Ok(HttpDate(s.parse().map_err(|_| Error(()))?))
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.