From babf48c550bcd27bded364caec7d0350846efba9 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 22 May 2019 21:21:12 -0700 Subject: [PATCH] fix NamedFile last-modified check #820 --- actix-files/CHANGES.md | 5 +++++ actix-files/src/named.rs | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/actix-files/CHANGES.md b/actix-files/CHANGES.md index 6b4ab57b8..e8457f42f 100644 --- a/actix-files/CHANGES.md +++ b/actix-files/CHANGES.md @@ -1,5 +1,10 @@ # Changes +## [0.1.0] - 2019-05-xx + +* NamedFile last-modified check always fails due to nano-seconds + in file modified date #820 + ## [0.1.0-beta.4] - 2019-05-12 * Update actix-web to beta.4 diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs index 41a7cf1f9..2298e35af 100644 --- a/actix-files/src/named.rs +++ b/actix-files/src/named.rs @@ -337,7 +337,12 @@ impl Responder for NamedFile { } else if let (Some(ref m), Some(header::IfUnmodifiedSince(ref since))) = (last_modified, req.get_header()) { - m > since + let t1: SystemTime = m.clone().into(); + let t2: SystemTime = since.clone().into(); + match (t1.duration_since(UNIX_EPOCH), t2.duration_since(UNIX_EPOCH)) { + (Ok(t1), Ok(t2)) => t1 > t2, + _ => false, + } } else { false }; @@ -350,7 +355,12 @@ impl Responder for NamedFile { } else if let (Some(ref m), Some(header::IfModifiedSince(ref since))) = (last_modified, req.get_header()) { - m <= since + let t1: SystemTime = m.clone().into(); + let t2: SystemTime = since.clone().into(); + match (t1.duration_since(UNIX_EPOCH), t2.duration_since(UNIX_EPOCH)) { + (Ok(t1), Ok(t2)) => t1 <= t2, + _ => false, + } } else { false };