Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add if-match support for OSS #2034

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions core/src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -434,7 +434,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();
Expand Down Expand Up @@ -479,10 +479,12 @@ 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, 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)?
.oss_get_object_request(path, v.range(), true, None, None)?
}
PresignOperation::Write(v) => self.core.oss_put_object_request(
path,
Expand Down
15 changes: 13 additions & 2 deletions core/src/services/oss/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,6 +149,7 @@ impl OssCore {
path: &str,
range: BytesRange,
is_presign: bool,
if_match: Option<&str>,
if_none_match: Option<&str>,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);
Expand All @@ -164,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);
}
Expand Down Expand Up @@ -192,13 +197,17 @@ impl OssCore {
&self,
path: &str,
is_presign: bool,
if_match: Option<&str>,
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 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);
}
Expand Down Expand Up @@ -239,9 +248,10 @@ impl OssCore {
&self,
path: &str,
range: BytesRange,
if_match: Option<&str>,
if_none_match: Option<&str>,
) -> Result<Response<IncomingAsyncBody>> {
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
Expand All @@ -250,9 +260,10 @@ impl OssCore {
pub async fn oss_head_object(
&self,
path: &str,
if_match: Option<&str>,
if_none_match: Option<&str>,
) -> Result<Response<IncomingAsyncBody>> {
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
Expand Down