Skip to content

Commit

Permalink
Respect content_type prop (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
vajexal authored Oct 25, 2024
1 parent b254b2f commit 2ce4fef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
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>,
}

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

0 comments on commit 2ce4fef

Please sign in to comment.