Skip to content

Commit

Permalink
Use strip_prefix and mutable attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
criccomini committed Jun 19, 2024
1 parent f7bb58b commit ba2a828
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions object_store/src/client/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn get_result<T: GetClient>(
}}
}

let attributes = parse_attributes!(
let mut attributes = parse_attributes!(
response.headers(),
(
CACHE_CONTROL,
Expand Down Expand Up @@ -222,21 +222,19 @@ fn get_result<T: GetClient>(
);

// Add attributes that match the user-defined metadata prefix (e.g. x-amz-meta-)
let attributes = if let Some(prefix) = T::HEADER_CONFIG.user_defined_metadata_prefix {
if let Some(prefix) = T::HEADER_CONFIG.user_defined_metadata_prefix {
let mut attributes = attributes.clone();
for (key, val) in response.headers() {
if key.as_str().starts_with(prefix) {
let suffix = key.as_str()[prefix.len()..].to_string();
attributes.insert(
Attribute::Metadata(suffix),
val.to_str().unwrap().to_string().into(),
);
if let Some(suffix) = key.as_str().strip_prefix(prefix) {
if let Ok(val_str) = val.to_str() {
attributes.insert(
Attribute::Metadata(suffix.to_string()),
val_str.to_string().into(),
);
}
}
}
attributes
} else {
attributes
};
};
}

let stream = response
.bytes_stream()
Expand Down

0 comments on commit ba2a828

Please sign in to comment.