This is an automated email from the ASF dual-hosted git repository.
Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new f5c1ed02be fix(services/b2): return stored Cache-Control from stat
(#9308)
f5c1ed02be is described below
commit f5c1ed02be18c381d30e54923dbed047e4fc8a66
Author: Xuanwo <[email protected]>
AuthorDate: Sat Nov 28 06:21:09 2026 +0800
fix(services/b2): return stored Cache-Control from stat (#9308)
fix(services/b2): expose stored Cache-Control in file metadata
Read the reserved B2 file-info value verbatim so stat can return the policy
stored by a presigned upload. Keep the existing user metadata decoding and the
independent custom cache-control entry.
Refs #6274
---
core/services/b2/src/backend.rs | 24 +++++++++++++++++++-----
core/services/b2/src/core.rs | 4 ++++
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/core/services/b2/src/backend.rs b/core/services/b2/src/backend.rs
index 8470ce4bb9..2e8989495b 100644
--- a/core/services/b2/src/backend.rs
+++ b/core/services/b2/src/backend.rs
@@ -768,7 +768,10 @@ mod tests {
r#"{"files":[{"fileName":"root/dir/","contentLength":0}]}"#
} else {
assert!(query.contains("prefix=root/file"));
-
r#"{"files":[{"fileName":"root/file","fileId":"new","contentLength":13,"fileInfo":{"content-disposition":"inline"}}]}"#
+ r#"{"files":[{
+
"fileName":"root/file","fileId":"new","contentLength":13,
+
"fileInfo":{"content-disposition":"inline","cache-control":"no-store"}
+ }]}"#
};
(StatusCode::OK, body)
}
@@ -809,6 +812,8 @@ mod tests {
"bucketId":"bucket-id","fileName":"root/file","fileId":"old","action":"upload",
"contentLength":5,"contentType":"text/plain","contentMd5":"md5",
"fileInfo":{
+ "b2-cache-control":"private, max-age=137,
no-cache=\"x-probe%20\"",
+ "cache-control":"max-age=19",
"Owner":"a%2Bb",
"b2-content-disposition":"attachment; filename=\"OpenDAL
%20 + probe.txt\""
}
@@ -821,12 +826,21 @@ mod tests {
assert_eq!(old.content_length(), 5);
assert_eq!(old.content_type(), Some("text/plain"));
assert_eq!(old.content_md5(), Some("md5"));
+ assert_eq!(
+ old.cache_control(),
+ Some(r#"private, max-age=137, no-cache="x-probe%20""#)
+ );
assert_eq!(
old.content_disposition(),
Some("attachment; filename=\"OpenDAL %20 + probe.txt\"")
);
let user_metadata = old.user_metadata().unwrap();
assert_eq!(user_metadata.get("owner"), Some("a+b"));
+ assert_eq!(
+ user_metadata.get("b2-cache-control"),
+ Some(r#"private, max-age=137, no-cache="x-probe ""#)
+ );
+ assert_eq!(user_metadata.get("cache-control"), Some("max-age=19"));
assert_eq!(
user_metadata.get("b2-content-disposition"),
Some("attachment; filename=\"OpenDAL + probe.txt\"")
@@ -835,11 +849,11 @@ mod tests {
let current = op.stat("file").await?;
assert_eq!(current.version(), Some("new"));
assert_eq!(current.content_length(), 13);
+ assert_eq!(current.cache_control(), None);
assert_eq!(current.content_disposition(), None);
- assert_eq!(
- current.user_metadata().unwrap().get("content-disposition"),
- Some("inline")
- );
+ let user_metadata = current.user_metadata().unwrap();
+ assert_eq!(user_metadata.get("cache-control"), Some("no-store"));
+ assert_eq!(user_metadata.get("content-disposition"), Some("inline"));
let op = stat_operator(
StatusCode::OK,
diff --git a/core/services/b2/src/core.rs b/core/services/b2/src/core.rs
index d69a218f91..ff54cd4dc1 100644
--- a/core/services/b2/src/core.rs
+++ b/core/services/b2/src/core.rs
@@ -1025,6 +1025,10 @@ pub(super) fn parse_file_info(file: &File) ->
MetadataBuilder {
metadata.content_type(content_type);
}
+ if let Some(cache_control) =
file.file_info.get(constants::CACHE_CONTROL_FILE_INFO_KEY) {
+ metadata.cache_control(cache_control);
+ }
+
if let Some(content_disposition) = file
.file_info
.get(constants::CONTENT_DISPOSITION_FILE_INFO_KEY)