From 5b96c0134bf152b7a5c165ee6ec075ce309d1cfd Mon Sep 17 00:00:00 2001 From: William Date: Fri, 8 Feb 2019 00:52:06 +0100 Subject: [PATCH] Ignored the If-Modified-Since if If-None-Match is specified (#680) --- src/fs.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/fs.rs b/src/fs.rs index dcf6c539a..3e1305e14 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -441,6 +441,8 @@ impl Responder for NamedFile { // check last modified let not_modified = if !none_match(etag.as_ref(), req) { true + } else if req.headers().contains_key(header::IF_NONE_MATCH) { + false } else if let (Some(ref m), Some(header::IfModifiedSince(ref since))) = (last_modified, req.get_header()) { @@ -944,6 +946,8 @@ impl HttpRange { #[cfg(test)] mod tests { use std::fs; + use std::time::Duration; + use std::ops::Add; use super::*; use application::App; @@ -963,6 +967,33 @@ mod tests { assert_eq!(m, mime::APPLICATION_OCTET_STREAM); } + #[test] + fn test_if_modified_since_ignored() { + assert!(NamedFile::open("test--").is_err()); + let mut file = NamedFile::open("Cargo.toml") + .unwrap() + .set_cpu_pool(CpuPool::new(1)); + { + file.file(); + let _f: &File = &file; + } + { + let _f: &mut File = &mut file; + } + let since = header::HttpDate::from( + SystemTime::now().add(Duration::from_secs(60))); + + let req = TestRequest::default() + .header(header::IF_NONE_MATCH, "miss_etag") + .header(header::IF_MODIFIED_SINCE, since) + .finish(); + let resp = file.respond_to(&req).unwrap(); + assert_ne!( + resp.status(), + StatusCode::NOT_MODIFIED + ); + } + #[test] fn test_named_file_text() { assert!(NamedFile::open("test--").is_err());