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

feat: gcs insert object support cache control #2974

Merged
merged 1 commit into from
Aug 31, 2023
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
9 changes: 6 additions & 3 deletions core/src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,12 @@ impl Accessor for GcsBackend {
}

async fn create_dir(&self, path: &str, _: OpCreateDir) -> Result<RpCreateDir> {
let mut req = self
.core
.gcs_insert_object_request(path, Some(0), None, AsyncBody::Empty)?;
let mut req = self.core.gcs_insert_object_request(
path,
Some(0),
&OpWrite::default(),
AsyncBody::Empty,
)?;

self.core.sign(&mut req).await?;

Expand Down
20 changes: 15 additions & 5 deletions core/src/services/gcs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// 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;
Expand Down Expand Up @@ -208,7 +209,7 @@ impl GcsCore {
&self,
path: &str,
size: Option<u64>,
content_type: Option<&str>,
op: &OpWrite,
body: AsyncBody,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);
Expand All @@ -233,7 +234,16 @@ impl GcsCore {

req = req.header(CONTENT_LENGTH, size.unwrap_or_default());

if let Some(storage_class) = &self.default_storage_class {
let mut meta_data = HashMap::new();
if let Some(content_type) = op.content_type() {
meta_data.insert("storageClass".to_string(), content_type.to_string());
}

if let Some(cache_control) = op.cache_control() {
meta_data.insert("cacheControl".to_string(), cache_control.to_string());
}

if !meta_data.is_empty() {
let mut multipart = Multipart::new();

multipart = multipart.part(
Expand All @@ -242,12 +252,12 @@ impl GcsCore {
CONTENT_TYPE,
"application/json; charset=UTF-8".parse().unwrap(),
)
.content(json!({"storageClass": storage_class}).to_string()),
.content(json!(meta_data).to_string()),
);

let mut media_part = FormDataPart::new("media").header(
CONTENT_TYPE,
content_type
op.content_type()
.unwrap_or("application/octet-stream")
.parse()
.unwrap(),
Expand All @@ -268,7 +278,7 @@ impl GcsCore {
let req = multipart.apply(Request::post(url))?;
Ok(req)
} else {
if let Some(content_type) = content_type {
if let Some(content_type) = op.content_type() {
req = req.header(CONTENT_TYPE, content_type);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/gcs/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl GcsWriter {
let mut req = self.core.gcs_insert_object_request(
&percent_encode_path(&self.path),
Some(size),
self.op.content_type(),
&self.op,
body,
)?;

Expand Down