1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

Ignored the If-Modified-Since if If-None-Match is specified (#680) (#692)

This commit is contained in:
cuebyte 2019-02-08 22:33:00 +01:00 committed by Douman
parent b018e4abaf
commit c695358bcb
2 changed files with 45 additions and 0 deletions

View File

@ -6,6 +6,10 @@
* Add `from_file` and `from_file_with_config` to `NamedFile` to allow sending files without a known path. #670
### Fixed
* Ignored the `If-Modified-Since` if `If-None-Match` is specified. #680
## [0.7.18] - 2019-01-10
### Added

View File

@ -441,6 +441,8 @@ impl<C: StaticFileConfig> Responder for NamedFile<C> {
// 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,43 @@ mod tests {
assert_eq!(m, mime::APPLICATION_OCTET_STREAM);
}
#[test]
fn test_if_modified_since_without_if_none_match() {
let mut file = NamedFile::open("Cargo.toml")
.unwrap()
.set_cpu_pool(CpuPool::new(1));
let since = header::HttpDate::from(
SystemTime::now().add(Duration::from_secs(60)));
let req = TestRequest::default()
.header(header::IF_MODIFIED_SINCE, since)
.finish();
let resp = file.respond_to(&req).unwrap();
assert_eq!(
resp.status(),
StatusCode::NOT_MODIFIED
);
}
#[test]
fn test_if_modified_since_with_if_none_match() {
let mut file = NamedFile::open("Cargo.toml")
.unwrap()
.set_cpu_pool(CpuPool::new(1));
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());