From 561f91ed7cef29f82caa8f07c1498c1a31c5b558 Mon Sep 17 00:00:00 2001 From: renkai Date: Wed, 19 Apr 2023 07:56:03 +0800 Subject: [PATCH 1/2] add if-match support --- core/src/services/oss/backend.rs | 6 ++++-- core/src/services/oss/core.rs | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/src/services/oss/backend.rs b/core/src/services/oss/backend.rs index b3077c7b1149..3bc6a6347903 100644 --- a/core/src/services/oss/backend.rs +++ b/core/src/services/oss/backend.rs @@ -450,7 +450,7 @@ impl Accessor for OssBackend { let resp = self .core - .oss_head_object(path, args.if_none_match()) + .oss_head_object(path, args.if_match(), args.if_none_match()) .await?; let status = resp.status(); @@ -495,7 +495,9 @@ impl Accessor for OssBackend { async fn presign(&self, path: &str, args: OpPresign) -> Result { // We will not send this request out, just for signing. let mut req = match args.operation() { - PresignOperation::Stat(_) => self.core.oss_head_object_request(path, true, None)?, + PresignOperation::Stat(_) => { + self.core.oss_head_object_request(path, true, None, None)? + } PresignOperation::Read(v) => { self.core .oss_get_object_request(path, v.range(), true, None)? diff --git a/core/src/services/oss/core.rs b/core/src/services/oss/core.rs index 6922869c6dae..7481bbc29f8a 100644 --- a/core/src/services/oss/core.rs +++ b/core/src/services/oss/core.rs @@ -24,6 +24,7 @@ use http::header::CACHE_CONTROL; use http::header::CONTENT_DISPOSITION; use http::header::CONTENT_LENGTH; use http::header::CONTENT_TYPE; +use http::header::IF_MATCH; use http::header::IF_NONE_MATCH; use http::header::RANGE; use http::Request; @@ -192,6 +193,7 @@ impl OssCore { &self, path: &str, is_presign: bool, + if_match: Option<&str>, if_none_match: Option<&str>, ) -> Result> { let p = build_abs_path(&self.root, path); @@ -199,6 +201,9 @@ impl OssCore { let url = format!("{}/{}", endpoint, percent_encode_path(&p)); let mut req = Request::head(&url); + if let Some(if_match) = if_match { + req = req.header(IF_MATCH, if_match) + } if let Some(if_none_match) = if_none_match { req = req.header(IF_NONE_MATCH, if_none_match); } @@ -250,9 +255,10 @@ impl OssCore { pub async fn oss_head_object( &self, path: &str, + if_match: Option<&str>, if_none_match: Option<&str>, ) -> Result> { - let mut req = self.oss_head_object_request(path, false, if_none_match)?; + let mut req = self.oss_head_object_request(path, false, if_match, if_none_match)?; self.sign(&mut req).await?; self.send(req).await From f8d1e33b53fed5e1ced7eb09f4ab4dc4c23027ea Mon Sep 17 00:00:00 2001 From: renkai Date: Wed, 19 Apr 2023 21:07:40 +0800 Subject: [PATCH 2/2] add if match for get --- core/src/services/oss/backend.rs | 4 ++-- core/src/services/oss/core.rs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/services/oss/backend.rs b/core/src/services/oss/backend.rs index 2b22b498fffe..77f9aefa6cd6 100644 --- a/core/src/services/oss/backend.rs +++ b/core/src/services/oss/backend.rs @@ -392,7 +392,7 @@ impl Accessor for OssBackend { async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> { let resp = self .core - .oss_get_object(path, args.range(), args.if_none_match()) + .oss_get_object(path, args.range(), args.if_match(), args.if_none_match()) .await?; let status = resp.status(); @@ -484,7 +484,7 @@ impl Accessor for OssBackend { } PresignOperation::Read(v) => { self.core - .oss_get_object_request(path, v.range(), true, None)? + .oss_get_object_request(path, v.range(), true, None, None)? } PresignOperation::Write(v) => self.core.oss_put_object_request( path, diff --git a/core/src/services/oss/core.rs b/core/src/services/oss/core.rs index 7481bbc29f8a..8626e8e3958f 100644 --- a/core/src/services/oss/core.rs +++ b/core/src/services/oss/core.rs @@ -149,6 +149,7 @@ impl OssCore { path: &str, range: BytesRange, is_presign: bool, + if_match: Option<&str>, if_none_match: Option<&str>, ) -> Result> { let p = build_abs_path(&self.root, path); @@ -165,6 +166,9 @@ impl OssCore { req = req.header("x-oss-range-behavior", "standard"); } + if let Some(if_match) = if_match { + req = req.header(IF_MATCH, if_match) + } if let Some(if_none_match) = if_none_match { req = req.header(IF_NONE_MATCH, if_none_match); } @@ -244,9 +248,10 @@ impl OssCore { &self, path: &str, range: BytesRange, + if_match: Option<&str>, if_none_match: Option<&str>, ) -> Result> { - let mut req = self.oss_get_object_request(path, range, false, if_none_match)?; + let mut req = self.oss_get_object_request(path, range, false, if_match, if_none_match)?; self.sign(&mut req).await?; self.send(req).await