mirror of
https://github.com/servo/servo.git
synced 2025-07-23 23:33:43 +01:00
net: Stop using both versions of the time
crate in the cookie code (#33260)
`std::time` is good enough for us here. `cookie` is using `time 0.3`, but Servo can convert to standard library types when getting data from `cookie`. This reduces our direct dependencies and removes more use of the very old `time 0.1` series. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
1e9344cb5c
commit
6f333a8e29
9 changed files with 29 additions and 95 deletions
|
@ -23,8 +23,6 @@ hyper = { workspace = true }
|
|||
mime = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_bytes = { workspace = true }
|
||||
time = { workspace = true }
|
||||
time_03 = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_test = "1.0"
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
//! * `hyper::Method`
|
||||
//! * `hyper::Uri`
|
||||
//! * `mime::Mime`
|
||||
//! * `time::Tm`
|
||||
//!
|
||||
//! # How do I use a data type with a `HeaderMap` member with Serde?
|
||||
//!
|
||||
|
@ -78,7 +77,6 @@ use serde::de::{self, Error, MapAccess, SeqAccess, Visitor};
|
|||
use serde::ser::{SerializeMap, SerializeSeq};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde_bytes::{ByteBuf, Bytes};
|
||||
use time::{strptime, Tm};
|
||||
|
||||
/// Deserialises a `T` value with a given deserializer.
|
||||
///
|
||||
|
@ -604,43 +602,6 @@ impl<'de> Visitor<'de> for StatusVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for De<Tm> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct TmVisitor;
|
||||
|
||||
impl<'de> Visitor<'de> for TmVisitor {
|
||||
type Value = De<Tm>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a date and time according to RFC 3339")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
strptime(v, "%Y-%m-%dT%H:%M:%SZ")
|
||||
.map(De::new)
|
||||
.map_err(|e| E::custom(e.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_string(TmVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Serialize for Ser<'a, Tm> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.v.rfc3339().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for De<Uri> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
|
|
|
@ -15,7 +15,6 @@ use hyper::{Method, StatusCode, Uri};
|
|||
use hyper_serde::{De, Ser, Serde};
|
||||
use mime::Mime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use time::Tm;
|
||||
|
||||
fn is_supported<T>()
|
||||
where
|
||||
|
@ -33,6 +32,5 @@ fn supported() {
|
|||
is_supported::<Method>();
|
||||
is_supported::<Mime>();
|
||||
is_supported::<StatusCode>();
|
||||
is_supported::<Tm>();
|
||||
is_supported::<Uri>();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use cookie::{Cookie, CookieBuilder};
|
||||
use headers::ContentType;
|
||||
use http::header::{self, HeaderMap, HeaderValue};
|
||||
|
@ -15,7 +17,6 @@ use http::StatusCode;
|
|||
use hyper::{Method, Uri};
|
||||
use hyper_serde::{De, Ser};
|
||||
use serde_test::{assert_de_tokens, assert_ser_tokens, Token};
|
||||
use time_03::Duration;
|
||||
|
||||
#[test]
|
||||
fn test_content_type() {
|
||||
|
@ -32,7 +33,7 @@ fn test_cookie() {
|
|||
// string with a bunch of indices in it which apparently is different from the exact same
|
||||
// cookie but parsed as a bunch of strings.
|
||||
let cookie: Cookie = CookieBuilder::new("Hello", "World!")
|
||||
.max_age(Duration::seconds(42))
|
||||
.max_age(Duration::from_secs(42).try_into().unwrap_or_default())
|
||||
.domain("servo.org")
|
||||
.path("/")
|
||||
.secure(true)
|
||||
|
@ -111,17 +112,6 @@ fn test_raw_status() {
|
|||
assert_de_tokens(&De::new(raw_status), tokens);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tm() {
|
||||
use time::strptime;
|
||||
|
||||
let time = strptime("2017-02-22T12:03:31Z", "%Y-%m-%dT%H:%M:%SZ").unwrap();
|
||||
let tokens = &[Token::Str("2017-02-22T12:03:31Z")];
|
||||
|
||||
assert_ser_tokens(&Ser::new(&time), tokens);
|
||||
assert_de_tokens(&De::new(time), tokens);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_uri() {
|
||||
use std::str::FromStr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue