Skip to content

Commit

Permalink
feat: gcs support cache control (#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatelei authored Apr 25, 2023
1 parent 8fc4f89 commit ed1d362
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ impl Accessor for GcsBackend {
}

async fn create_dir(&self, path: &str, _: OpCreate) -> Result<RpCreate> {
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), None, None, AsyncBody::Empty)?;

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

Expand Down
6 changes: 6 additions & 0 deletions core/src/services/gcs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use backon::ExponentialBuilder;
use backon::Retryable;
use bytes::Bytes;
use bytes::BytesMut;
use http::header::CACHE_CONTROL;
use http::header::CONTENT_LENGTH;
use http::header::CONTENT_RANGE;
use http::header::CONTENT_TYPE;
Expand Down Expand Up @@ -150,6 +151,7 @@ impl GcsCore {
path: &str,
size: Option<usize>,
content_type: Option<&str>,
cache_control: Option<&str>,
body: AsyncBody,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);
Expand All @@ -174,6 +176,10 @@ impl GcsCore {

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

if let Some(cache_control) = cache_control {
req = req.header(CACHE_CONTROL, cache_control)
}

if let Some(storage_class) = &self.default_storage_class {
req = req.header(CONTENT_TYPE, "multipart/related; boundary=my-boundary");

Expand Down
1 change: 1 addition & 0 deletions core/src/services/gcs/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl GcsWriter {
&percent_encode_path(&self.path),
Some(bs.len()),
self.op.content_type(),
self.op.cache_control(),
AsyncBody::Bytes(bs),
)?;

Expand Down

0 comments on commit ed1d362

Please sign in to comment.