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 47d566fed4 fix(services/cos): preserve Content-Encoding on single PUT
(#9297)
47d566fed4 is described below
commit 47d566fed492dec31f4a90b235e20695363ec57a
Author: Xuanwo <[email protected]>
AuthorDate: Sat Nov 28 01:21:55 2026 +0800
fix(services/cos): preserve Content-Encoding on single PUT (#9297)
---
core/services/cos/src/backend.rs | 46 ++++++++++++++++++++++++++++++++++++++++
core/services/cos/src/core.rs | 4 ++++
2 files changed, 50 insertions(+)
diff --git a/core/services/cos/src/backend.rs b/core/services/cos/src/backend.rs
index 70db6946b1..96538d6ff2 100644
--- a/core/services/cos/src/backend.rs
+++ b/core/services/cos/src/backend.rs
@@ -616,8 +616,54 @@ fn build_endpoint(uri: &Uri, bucket: &str) ->
Result<String> {
#[cfg(test)]
mod tests {
+ use http::header::CONTENT_ENCODING;
+
use super::*;
+ #[tokio::test]
+ async fn presign_write_signs_optional_content_encoding() {
+ let op = Operator::new(
+ CosBuilder::default()
+ .bucket("test")
+ .endpoint("https://cos.example.com")
+ .secret_id("test")
+ .secret_key("test")
+ .disable_config_load(),
+ )
+ .unwrap();
+
+ for encoding in [Some("gzip"), None] {
+ let request = op
+ .presign_write_options(
+ "object.txt",
+ Duration::from_secs(60),
+ options::WriteOptions {
+ content_type: Some("text/plain".to_owned()),
+ content_encoding: encoding.map(str::to_owned),
+ ..Default::default()
+ },
+ )
+ .await
+ .unwrap();
+ let values: Vec<_> =
request.header().get_all(CONTENT_ENCODING).iter().collect();
+ assert_eq!(values.as_slice(), encoding.as_slice());
+
+ let signed_headers = request
+ .uri()
+ .query()
+ .unwrap()
+ .split('&')
+ .find_map(|param| param.strip_prefix("q-header-list="))
+ .map(percent_decode_path)
+ .expect("missing COS signed headers");
+ let signed_count = signed_headers
+ .split(';')
+ .filter(|name| *name == CONTENT_ENCODING.as_str())
+ .count();
+ assert_eq!(signed_count, usize::from(encoding.is_some()));
+ }
+ }
+
fn endpoint_of(raw: &str, bucket: &str) -> String {
build_endpoint(&raw.parse::<Uri>().unwrap(), bucket).unwrap()
}
diff --git a/core/services/cos/src/core.rs b/core/services/cos/src/core.rs
index b7900d300c..c583e5a87f 100644
--- a/core/services/cos/src/core.rs
+++ b/core/services/cos/src/core.rs
@@ -23,6 +23,7 @@ use http::Request;
use http::Response;
use http::header::CACHE_CONTROL;
use http::header::CONTENT_DISPOSITION;
+use http::header::CONTENT_ENCODING;
use http::header::CONTENT_LENGTH;
use http::header::CONTENT_TYPE;
use http::header::IF_MATCH;
@@ -210,6 +211,9 @@ impl CosCore {
if let Some(mime) = args.content_type() {
req = req.header(CONTENT_TYPE, mime)
}
+ if let Some(encoding) = args.content_encoding() {
+ req = req.header(CONTENT_ENCODING, encoding)
+ }
// For a bucket which has never enabled versioning, you may use it to
// specify whether to prohibit overwriting the object with the same
name