Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ pub enum Attribute {
///
/// The String is a user-defined key
Metadata(Cow<'static, str>),
/// Specifies an implementation-specific attribute to be sent with the object
///
/// Attribute is prefixed with implementation-defined prefixes are as follows:
/// - [`AWS`](crate::aws): `x-amz-`
/// - [`Azure`](crate::azure): `x-ms-`
/// - [`GCP`](crate::gcp): `x-goog-`
Other(Cow<'static, str>),
}

/// The value of an [`Attribute`]
Expand Down Expand Up @@ -199,10 +206,11 @@ mod tests {
(Attribute::ContentType, "test"),
(Attribute::CacheControl, "control"),
(Attribute::Metadata("key1".into()), "value1"),
(Attribute::Other("key2".into()), "value2"),
]);

assert!(!attributes.is_empty());
assert_eq!(attributes.len(), 6);
assert_eq!(attributes.len(), 7);

assert_eq!(
attributes.get(&Attribute::ContentType),
Expand All @@ -215,18 +223,18 @@ mod tests {
attributes.insert(Attribute::CacheControl, "v1".into()),
Some(metav)
);
assert_eq!(attributes.len(), 6);
assert_eq!(attributes.len(), 7);

assert_eq!(
attributes.remove(&Attribute::CacheControl).unwrap(),
"v1".into()
);
assert_eq!(attributes.len(), 5);
assert_eq!(attributes.len(), 6);

let metav: AttributeValue = "v2".into();
attributes.insert(Attribute::CacheControl, metav.clone());
assert_eq!(attributes.get(&Attribute::CacheControl), Some(&metav));
assert_eq!(attributes.len(), 6);
assert_eq!(attributes.len(), 7);

assert_eq!(
attributes.get(&Attribute::ContentDisposition),
Expand All @@ -244,5 +252,9 @@ mod tests {
attributes.get(&Attribute::Metadata("key1".into())),
Some(&"value1".into())
);
assert_eq!(
attributes.get(&Attribute::Other("key2".into())),
Some(&"value2".into())
);
}
}
5 changes: 5 additions & 0 deletions src/aws/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use std::sync::Arc;

const VERSION_HEADER: &str = "x-amz-version-id";
const SHA256_CHECKSUM: &str = "x-amz-checksum-sha256";
const IMPL_DEFINED_ATTR_HEADER_PREFIX: &str = "x-amz-";
const USER_DEFINED_METADATA_HEADER_PREFIX: &str = "x-amz-meta-";
const ALGORITHM: &str = "x-amz-checksum-algorithm";

Expand Down Expand Up @@ -377,6 +378,10 @@ impl Request<'_> {
&format!("{USER_DEFINED_METADATA_HEADER_PREFIX}{k_suffix}"),
v.as_ref(),
),
Attribute::Other(attr) => builder.header(
&format!("{IMPL_DEFINED_ATTR_HEADER_PREFIX}{attr}"),
v.as_ref(),
),
};
}

Expand Down
5 changes: 5 additions & 0 deletions src/azure/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use url::Url;

const VERSION_HEADER: &str = "x-ms-version-id";
const USER_DEFINED_METADATA_HEADER_PREFIX: &str = "x-ms-meta-";
const IMPL_DEFINED_ATTR_HEADER_PREFIX: &str = "x-ms-";
static MS_CACHE_CONTROL: HeaderName = HeaderName::from_static("x-ms-blob-cache-control");
static MS_CONTENT_TYPE: HeaderName = HeaderName::from_static("x-ms-blob-content-type");
static MS_CONTENT_DISPOSITION: HeaderName =
Expand Down Expand Up @@ -246,6 +247,10 @@ impl PutRequest<'_> {
&format!("{USER_DEFINED_METADATA_HEADER_PREFIX}{k_suffix}"),
v.as_ref(),
),
Attribute::Other(attr) => builder.header(
&format!("{IMPL_DEFINED_ATTR_HEADER_PREFIX}{attr}"),
v.as_ref(),
),
};
}

Expand Down
5 changes: 5 additions & 0 deletions src/gcp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use std::sync::Arc;
const VERSION_HEADER: &str = "x-goog-generation";
const DEFAULT_CONTENT_TYPE: &str = "application/octet-stream";
const USER_DEFINED_METADATA_HEADER_PREFIX: &str = "x-goog-meta-";
const IMPL_DEFINED_ATTR_HEADER_PREFIX: &str = "x-goog-";

static VERSION_MATCH: HeaderName = HeaderName::from_static("x-goog-if-generation-match");

Expand Down Expand Up @@ -205,6 +206,10 @@ impl Request<'_> {
&format!("{USER_DEFINED_METADATA_HEADER_PREFIX}{k_suffix}"),
v.as_ref(),
),
Attribute::Other(attr) => builder.header(
&format!("{IMPL_DEFINED_ATTR_HEADER_PREFIX}{attr}"),
v.as_ref(),
),
};
}

Expand Down
1 change: 1 addition & 0 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ impl Client {
}
// Ignore metadata attributes
Attribute::Metadata(_) => builder,
Attribute::Other(attr) => builder.header(&**attr, v.as_ref()),
};
}

Expand Down