Skip to content

Commit

Permalink
test passes
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Aug 1, 2020
1 parent 4864e5e commit 93c3f4c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/cache/cache_control/cache_control.rs
Expand Up @@ -29,7 +29,9 @@ impl CacheControl {
for part in value.as_str().trim().split(',') {
// Try and parse a directive from a str. If the directive is
// unkown we skip it.
if let Some(entry) = CacheDirective::from_str(part.trim_start())? {
let s = part.trim_start();
s.to_lowercase();
if let Some(entry) = CacheDirective::from_str(s)? {
entries.push(entry);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/cache/cache_control/cache_directive.rs
Expand Up @@ -4,7 +4,7 @@ use crate::Status;
use std::time::Duration;

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

// This won't panic because each input string has at least one part.
let res = match next {
"immutable" => Some(Immutable),
"no-cache" => Some(NoCache),
"no-store" => Some(NoStore),
"no-transform" => Some(NoTransform),
Expand Down
22 changes: 22 additions & 0 deletions src/cache/cache_control/mod.rs
Expand Up @@ -11,3 +11,25 @@ mod cache_directive;

pub use cache_control::CacheControl;
pub use cache_directive::CacheDirective;

#[cfg(test)]
mod test {
use super::*;
use crate::headers::Headers;

#[test]
fn smoke() -> crate::Result<()> {
let mut entries = CacheControl::new();
entries.push(CacheDirective::Immutable);
entries.push(CacheDirective::NoStore);

let mut headers = Headers::new();
entries.apply(&mut headers);

let entries = CacheControl::from_headers(headers)?.unwrap();
let mut entries = entries.iter();
assert_eq!(entries.next().unwrap(), &CacheDirective::Immutable);
assert_eq!(entries.next().unwrap(), &CacheDirective::NoStore);
Ok(())
}
}

0 comments on commit 93c3f4c

Please sign in to comment.