Skip to content

Commit 93c3f4c

Browse files
committed
test passes
1 parent 4864e5e commit 93c3f4c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/cache/cache_control/cache_control.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ impl CacheControl {
2929
for part in value.as_str().trim().split(',') {
3030
// Try and parse a directive from a str. If the directive is
3131
// unkown we skip it.
32-
if let Some(entry) = CacheDirective::from_str(part.trim_start())? {
32+
let s = part.trim_start();
33+
s.to_lowercase();
34+
if let Some(entry) = CacheDirective::from_str(s)? {
3335
entries.push(entry);
3436
}
3537
}

src/cache/cache_control/cache_directive.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::Status;
44
use std::time::Duration;
55

66
/// An HTTP `Cache-Control` directive.
7-
#[derive(Debug, Clone)]
7+
#[derive(Debug, Clone, PartialEq, Eq)]
88
pub enum CacheDirective {
99
/// The response body will not change over time.
1010
Immutable,
@@ -87,6 +87,7 @@ impl CacheDirective {
8787

8888
// This won't panic because each input string has at least one part.
8989
let res = match next {
90+
"immutable" => Some(Immutable),
9091
"no-cache" => Some(NoCache),
9192
"no-store" => Some(NoStore),
9293
"no-transform" => Some(NoTransform),

src/cache/cache_control/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,25 @@ mod cache_directive;
1111

1212
pub use cache_control::CacheControl;
1313
pub use cache_directive::CacheDirective;
14+
15+
#[cfg(test)]
16+
mod test {
17+
use super::*;
18+
use crate::headers::Headers;
19+
20+
#[test]
21+
fn smoke() -> crate::Result<()> {
22+
let mut entries = CacheControl::new();
23+
entries.push(CacheDirective::Immutable);
24+
entries.push(CacheDirective::NoStore);
25+
26+
let mut headers = Headers::new();
27+
entries.apply(&mut headers);
28+
29+
let entries = CacheControl::from_headers(headers)?.unwrap();
30+
let mut entries = entries.iter();
31+
assert_eq!(entries.next().unwrap(), &CacheDirective::Immutable);
32+
assert_eq!(entries.next().unwrap(), &CacheDirective::NoStore);
33+
Ok(())
34+
}
35+
}

0 commit comments

Comments
 (0)