-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return the new object ETag in PutObjectResult (#1057)
* Return the ETag in PutObjectResult Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk> * Simplify handling of response headers Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk> * Move ETag to a separate module Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk> * Add comments Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk> --------- Signed-off-by: Alessandro Passaro <alexpax@amazon.co.uk>
- Loading branch information
Showing
6 changed files
with
141 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::str::FromStr; | ||
use std::string::ParseError; | ||
|
||
/// An ETag (entity tag) is a unique identifier for a HTTP object. | ||
/// | ||
/// New ETags can be created with the [`FromStr`] implementation. | ||
#[derive(Debug, Clone, Hash, PartialEq, Eq)] | ||
pub struct ETag(String); | ||
|
||
impl ETag { | ||
/// Get the ETag as a string | ||
pub fn as_str(&self) -> &str { | ||
&self.0 | ||
} | ||
|
||
/// Unpack the [String] contained by the [ETag] wrapper | ||
pub fn into_inner(self) -> String { | ||
self.0 | ||
} | ||
|
||
/// Creating default etag for tests | ||
#[doc(hidden)] | ||
pub fn for_tests() -> Self { | ||
Self("test_etag".to_string()) | ||
} | ||
|
||
/// Creating unique etag from bytes | ||
#[doc(hidden)] | ||
#[cfg(feature = "mock")] | ||
pub fn from_object_bytes(data: &[u8]) -> Self { | ||
use md5::Digest as _; | ||
|
||
let mut hasher = md5::Md5::new(); | ||
hasher.update(data); | ||
|
||
let hash = hasher.finalize(); | ||
let result = format!("{:x}", hash); | ||
Self(result) | ||
} | ||
} | ||
|
||
impl FromStr for ETag { | ||
type Err = ParseError; | ||
fn from_str(value: &str) -> Result<Self, Self::Err> { | ||
let etag = value.to_string(); | ||
Ok(ETag(etag)) | ||
} | ||
} | ||
|
||
impl<S: AsRef<str>> From<S> for ETag { | ||
fn from(value: S) -> Self { | ||
Self(value.as_ref().to_string()) | ||
} | ||
} |
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
Oops, something went wrong.