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/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new b182d1ef feat: add oss if-none-match support (#1997)
b182d1ef is described below
commit b182d1efe7673d25d7695d482734cec08a31773f
Author: x1a0t <[email protected]>
AuthorDate: Fri Apr 14 20:24:17 2023 +0800
feat: add oss if-none-match support (#1997)
* feat: add oss if-none-match support
* chore: simplify reference
* fix: cargo fmt
---
core/src/services/http/backend.rs | 5 +++--
core/src/services/oss/backend.rs | 19 ++++++++++++++-----
core/src/services/oss/core.rs | 24 +++++++++++++++++++-----
core/src/services/s3/core.rs | 8 ++++----
4 files changed, 40 insertions(+), 16 deletions(-)
diff --git a/core/src/services/http/backend.rs
b/core/src/services/http/backend.rs
index c4c0bdbc..21a42c71 100644
--- a/core/src/services/http/backend.rs
+++ b/core/src/services/http/backend.rs
@@ -21,6 +21,7 @@ use std::fmt::Formatter;
use async_trait::async_trait;
use http::header;
+use http::header::IF_NONE_MATCH;
use http::Request;
use http::Response;
use http::StatusCode;
@@ -314,7 +315,7 @@ impl HttpBackend {
let mut req = Request::get(&url);
if let Some(if_none_match) = if_none_match {
- req = req.header(http::header::IF_NONE_MATCH, if_none_match);
+ req = req.header(IF_NONE_MATCH, if_none_match);
}
if let Some(auth) = &self.authorization {
@@ -344,7 +345,7 @@ impl HttpBackend {
let mut req = Request::head(&url);
if let Some(if_none_match) = if_none_match {
- req = req.header(http::header::IF_NONE_MATCH, if_none_match);
+ req = req.header(IF_NONE_MATCH, if_none_match);
}
if let Some(auth) = &self.authorization {
diff --git a/core/src/services/oss/backend.rs b/core/src/services/oss/backend.rs
index 5bb24bc7..4458338d 100644
--- a/core/src/services/oss/backend.rs
+++ b/core/src/services/oss/backend.rs
@@ -388,7 +388,10 @@ 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()).await?;
+ let resp = self
+ .core
+ .oss_get_object(path, args.range(), args.if_none_match())
+ .await?;
let status = resp.status();
@@ -437,13 +440,16 @@ impl Accessor for OssBackend {
}
}
- async fn stat(&self, path: &str, _: OpStat) -> Result<RpStat> {
+ async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
if path == "/" {
let m = Metadata::new(EntryMode::DIR);
return Ok(RpStat::new(m));
}
- let resp = self.core.oss_head_object(path).await?;
+ let resp = self
+ .core
+ .oss_head_object(path, args.if_none_match())
+ .await?;
let status = resp.status();
@@ -487,8 +493,11 @@ impl Accessor for OssBackend {
async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
// 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)?,
- PresignOperation::Read(v) =>
self.core.oss_get_object_request(path, v.range(), true)?,
+ PresignOperation::Stat(_) =>
self.core.oss_head_object_request(path, true, None)?,
+ PresignOperation::Read(v) => {
+ self.core
+ .oss_get_object_request(path, v.range(), true, None)?
+ }
PresignOperation::Write(v) => self.core.oss_put_object_request(
path,
None,
diff --git a/core/src/services/oss/core.rs b/core/src/services/oss/core.rs
index 4f8d11ce..387d8b83 100644
--- a/core/src/services/oss/core.rs
+++ b/core/src/services/oss/core.rs
@@ -20,11 +20,11 @@ use std::fmt::Formatter;
use std::time::Duration;
use bytes::Bytes;
-use http::header::CACHE_CONTROL;
use http::header::CONTENT_DISPOSITION;
use http::header::CONTENT_LENGTH;
use http::header::CONTENT_TYPE;
use http::header::RANGE;
+use http::header::{CACHE_CONTROL, IF_NONE_MATCH};
use http::Request;
use http::Response;
use reqsign::AliyunCredential;
@@ -147,6 +147,7 @@ impl OssCore {
path: &str,
range: BytesRange,
is_presign: bool,
+ if_none_match: Option<&str>,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);
let endpoint = self.get_endpoint(is_presign);
@@ -162,6 +163,10 @@ impl OssCore {
req = req.header("x-oss-range-behavior", "standard");
}
+ if let Some(if_none_match) = if_none_match {
+ req = req.header(IF_NONE_MATCH, if_none_match);
+ }
+
let req = req
.body(AsyncBody::Empty)
.map_err(new_request_build_error)?;
@@ -186,12 +191,16 @@ impl OssCore {
&self,
path: &str,
is_presign: bool,
+ if_none_match: Option<&str>,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);
let endpoint = self.get_endpoint(is_presign);
let url = format!("{}/{}", endpoint, percent_encode_path(&p));
- let req = Request::head(&url);
+ let mut req = Request::head(&url);
+ if let Some(if_none_match) = if_none_match {
+ req = req.header(IF_NONE_MATCH, if_none_match);
+ }
let req = req
.body(AsyncBody::Empty)
.map_err(new_request_build_error)?;
@@ -229,15 +238,20 @@ impl OssCore {
&self,
path: &str,
range: BytesRange,
+ if_none_match: Option<&str>,
) -> Result<Response<IncomingAsyncBody>> {
- let mut req = self.oss_get_object_request(path, range, false)?;
+ let mut req = self.oss_get_object_request(path, range, false,
if_none_match)?;
self.sign(&mut req).await?;
self.send(req).await
}
- pub async fn oss_head_object(&self, path: &str) ->
Result<Response<IncomingAsyncBody>> {
- let mut req = self.oss_head_object_request(path, false)?;
+ pub async fn oss_head_object(
+ &self,
+ path: &str,
+ if_none_match: Option<&str>,
+ ) -> Result<Response<IncomingAsyncBody>> {
+ let mut req = self.oss_head_object_request(path, false,
if_none_match)?;
self.sign(&mut req).await?;
self.send(req).await
diff --git a/core/src/services/s3/core.rs b/core/src/services/s3/core.rs
index 3a33feff..4f099188 100644
--- a/core/src/services/s3/core.rs
+++ b/core/src/services/s3/core.rs
@@ -24,11 +24,11 @@ use std::time::Duration;
use backon::ExponentialBuilder;
use backon::Retryable;
use bytes::Bytes;
-use http::header::HeaderName;
use http::header::CACHE_CONTROL;
use http::header::CONTENT_DISPOSITION;
use http::header::CONTENT_LENGTH;
use http::header::CONTENT_TYPE;
+use http::header::{HeaderName, IF_NONE_MATCH};
use http::HeaderValue;
use http::Request;
use http::Response;
@@ -215,7 +215,7 @@ impl S3Core {
req = self.insert_sse_headers(req, false);
if let Some(if_none_match) = if_none_match {
- req = req.header(http::header::IF_NONE_MATCH, if_none_match);
+ req = req.header(IF_NONE_MATCH, if_none_match);
}
let req = req
@@ -265,7 +265,7 @@ impl S3Core {
}
if let Some(if_none_match) = if_none_match {
- req = req.header(http::header::IF_NONE_MATCH, if_none_match);
+ req = req.header(IF_NONE_MATCH, if_none_match);
}
// Set SSE headers.
@@ -352,7 +352,7 @@ impl S3Core {
req = self.insert_sse_headers(req, false);
if let Some(if_none_match) = if_none_match {
- req = req.header(http::header::IF_NONE_MATCH, if_none_match);
+ req = req.header(IF_NONE_MATCH, if_none_match);
}
let mut req = req