Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements an Entity Tag hash by obtaining the date created, the date of the last modification and the size of the file.
- Loading branch information
1 parent
72de4e2
commit 54be7c0
Showing
5 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::fs::Metadata; | ||
use std::time::SystemTime; | ||
use std::hash::{Hash, Hasher}; | ||
use std::collections::hash_map::DefaultHasher; | ||
|
||
/// Creates an Entity Tag from a `File` `Metadata` | ||
pub fn make_entity_tag(meta: &Metadata) -> String { | ||
let mut created_hasher = DefaultHasher::new(); | ||
let mut modified_hasher = DefaultHasher::new(); | ||
let mut size_hasher = DefaultHasher::new(); | ||
|
||
meta.len().hash(&mut size_hasher); | ||
meta.created().unwrap_or(SystemTime::now()).hash(&mut created_hasher); | ||
meta.modified().unwrap_or(SystemTime::now()).hash(&mut modified_hasher); | ||
|
||
format!("{0:x}{1:x}{2:x}", created_hasher.finish(), modified_hasher.finish(), size_hasher.finish()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod etag; | ||
mod http; | ||
|
||
pub use etag::*; | ||
pub use http::*; |