Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect content_type prop #100

Merged
merged 3 commits into from
Oct 25, 2024
Merged
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
24 changes: 20 additions & 4 deletions src/s3/builders/put_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct CreateMultipartUpload {
tags: Option<HashMap<String, String>>,
retention: Option<Retention>,
legal_hold: bool,
content_type: Option<String>,
donatello marked this conversation as resolved.
Show resolved Hide resolved
}

impl CreateMultipartUpload {
Expand Down Expand Up @@ -108,6 +109,11 @@ impl CreateMultipartUpload {
self
}

pub fn content_type(mut self, content_type: Option<String>) -> Self {
self.content_type = content_type;
self
}

fn get_headers(&self) -> Result<Multimap, Error> {
object_write_args_headers(
self.extra_headers.as_ref(),
Expand All @@ -116,6 +122,7 @@ impl CreateMultipartUpload {
self.tags.as_ref(),
self.retention.as_ref(),
self.legal_hold,
self.content_type.as_ref(),
)
}

Expand Down Expand Up @@ -376,6 +383,7 @@ pub struct UploadPart {
retention: Option<Retention>,
legal_hold: bool,
data: SegmentedBytes,
content_type: Option<String>,

// This is used only when this struct is used for PutObject.
user_metadata: Option<Multimap>,
Expand Down Expand Up @@ -452,6 +460,7 @@ impl UploadPart {
self.tags.as_ref(),
self.retention.as_ref(),
self.legal_hold,
self.content_type.as_ref(),
)
}

Expand Down Expand Up @@ -597,6 +606,7 @@ fn object_write_args_headers(
tags: Option<&HashMap<String, String>>,
retention: Option<&Retention>,
legal_hold: bool,
content_type: Option<&String>,
) -> Result<Multimap, Error> {
let mut map = Multimap::new();

Expand Down Expand Up @@ -662,7 +672,10 @@ fn object_write_args_headers(
if !map.contains_key("Content-Type") {
map.insert(
String::from("Content-Type"),
String::from("application/octet-stream"),
match content_type {
Some(content_type) => content_type.clone(),
None => String::from("application/octet-stream"),
},
);
}

Expand All @@ -686,7 +699,7 @@ pub struct PutObjectContent {
retention: Option<Retention>,
legal_hold: bool,
part_size: Size,
content_type: String,
content_type: Option<String>,

// source data
input_content: ObjectContent,
Expand All @@ -713,7 +726,7 @@ impl PutObjectContent {
retention: None,
legal_hold: false,
part_size: Size::Unknown,
content_type: String::from("application/octet-stream"),
content_type: None,
content_stream: ContentStream::empty(),
part_count: None,
}
Expand Down Expand Up @@ -770,7 +783,7 @@ impl PutObjectContent {
}

pub fn content_type(mut self, content_type: String) -> Self {
self.content_type = content_type;
self.content_type = Some(content_type);
self
}

Expand Down Expand Up @@ -965,6 +978,7 @@ impl PutObjectContent {
part_number: None,
upload_id: None,
data,
content_type: self.content_type.clone(),
})
}

Expand All @@ -990,6 +1004,7 @@ impl PutObjectContent {
part_number: Some(part_number),
upload_id: Some(upload_id.to_string()),
data,
content_type: self.content_type.clone(),
}
}

Expand Down Expand Up @@ -1023,6 +1038,7 @@ impl PutObjectContent {
tags: self.tags.clone(),
retention: self.retention.clone(),
legal_hold: self.legal_hold,
content_type: self.content_type.clone(),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use async_std::task;
use bytes::Bytes;
use chrono::Duration;
use futures_util::Stream;
use http::header;
use hyper::http::Method;

use minio::s3::builders::{ObjectContent, ObjectToDelete};
Expand Down Expand Up @@ -339,6 +340,7 @@ impl ClientTest {
&object_name,
ObjectContent::new_from_stream(data_src, Some(*size)),
)
.content_type(String::from("image/jpeg"))
.send()
.await
.unwrap();
Expand All @@ -351,6 +353,10 @@ impl ClientTest {
.unwrap();
assert_eq!(resp.size, *size as usize);
assert_eq!(resp.etag, etag);
assert_eq!(
resp.headers.get(header::CONTENT_TYPE).unwrap(),
"image/jpeg"
);
self.client
.remove_object(&self.test_bucket, object_name.as_str())
.send()
Expand Down