Skip to content

Commit

Permalink
refactor: apply parse_prefixed_metadata for oss
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgehermo9 committed Nov 2, 2024
1 parent d28eae6 commit 7bac4cd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 33 deletions.
1 change: 0 additions & 1 deletion core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use reqsign::AzureStorageSigner;
use sha2::Digest;
use sha2::Sha256;

use super::core::constants;
use super::core::constants::X_MS_META_NAME_PREFIX;
use super::error::parse_error;
use super::lister::AzblobLister;
Expand Down
4 changes: 1 addition & 3 deletions core/src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,7 @@ impl Access for OssBackend {
match status {
StatusCode::OK => {
let headers = resp.headers();
let mut meta =
self.core
.parse_metadata(path, constants::X_OSS_META_PREFIX, resp.headers())?;
let mut meta = self.core.parse_metadata(path, resp.headers())?;

if let Some(v) = parse_header_to_str(headers, "x-oss-version-id")? {
meta.set_version(v);
Expand Down
29 changes: 6 additions & 23 deletions core/src/services/oss/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
// specific language governing permissions and limitations
// under the License.

use std::collections::HashMap;
use std::fmt::Debug;
use std::fmt::Formatter;
use std::fmt::Write;
use std::time::Duration;

use bytes::Bytes;
use constants::X_OSS_META_PREFIX;
use http::header::CACHE_CONTROL;
use http::header::CONTENT_DISPOSITION;
use http::header::CONTENT_LENGTH;
Expand Down Expand Up @@ -190,7 +190,7 @@ impl OssCore {
"the format of the user metadata key is invalid, please refer the document",
));
}
req = req.header(format!("{}{}", constants::X_OSS_META_PREFIX, key), value)
req = req.header(format!("{X_OSS_META_PREFIX}{key}"), value)
}
}

Expand All @@ -213,28 +213,11 @@ impl OssCore {
/// # Notes
///
/// before return the user defined metadata, we'll strip the user_metadata_prefix from the key
pub fn parse_metadata(
&self,
path: &str,
user_metadata_prefix: &str,
headers: &HeaderMap,
) -> Result<Metadata> {
pub fn parse_metadata(&self, path: &str, headers: &HeaderMap) -> Result<Metadata> {
let mut m = parse_into_metadata(path, headers)?;

let data: HashMap<String, String> = headers
.iter()
.filter_map(|(key, _)| {
key.as_str()
.strip_prefix(user_metadata_prefix)
.and_then(|stripped_key| {
parse_header_to_str(headers, key)
.unwrap_or(None)
.map(|val| (stripped_key.to_string(), val.to_string()))
})
})
.collect();
if !data.is_empty() {
m.with_user_metadata(data);
let user_meta = parse_prefixed_headers(&headers, X_OSS_META_PREFIX);
if !user_meta.is_empty() {
m.with_user_metadata(user_meta);
}

Ok(m)
Expand Down
12 changes: 6 additions & 6 deletions core/src/services/oss/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
// specific language governing permissions and limitations
// under the License.

#[cfg(feature = "services-oss")]
// #[cfg(feature = "services-oss")]
mod core;
#[cfg(feature = "services-oss")]
// #[cfg(feature = "services-oss")]
mod error;
#[cfg(feature = "services-oss")]
// #[cfg(feature = "services-oss")]
mod lister;
#[cfg(feature = "services-oss")]
// #[cfg(feature = "services-oss")]
mod writer;

#[cfg(feature = "services-oss")]
// #[cfg(feature = "services-oss")]
mod backend;
#[cfg(feature = "services-oss")]
// #[cfg(feature = "services-oss")]
pub use backend::OssBuilder as Oss;

mod config;
Expand Down

0 comments on commit 7bac4cd

Please sign in to comment.