Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add if_none_match support for azblob #2035

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,10 @@ impl Accessor for AzblobBackend {
}

async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
let resp = self.core.azblob_get_blob(path, args.range()).await?;
let resp = self
.core
.azblob_get_blob(path, args.range(), args.if_none_match())
.await?;

let status = resp.status();

Expand Down Expand Up @@ -524,13 +527,16 @@ impl Accessor for AzblobBackend {
}
}

async fn stat(&self, path: &str, _: OpStat) -> Result<RpStat> {
async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
// Stat root always returns a DIR.
if path == "/" {
return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
}

let resp = self.core.azblob_get_blob_properties(path).await?;
let resp = self
.core
.azblob_get_blob_properties(path, args.if_none_match())
.await?;

let status = resp.status();

Expand Down
13 changes: 12 additions & 1 deletion core/src/services/azblob/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::str::FromStr;
use http::header::HeaderName;
use http::header::CONTENT_LENGTH;
use http::header::CONTENT_TYPE;
use http::header::IF_NONE_MATCH;
use http::Request;
use http::Response;
use http::Uri;
Expand Down Expand Up @@ -100,6 +101,7 @@ impl AzblobCore {
&self,
path: &str,
range: BytesRange,
if_none_match: Option<&str>,
) -> Result<Response<IncomingAsyncBody>> {
let p = build_abs_path(&self.root, path);

Expand All @@ -126,6 +128,10 @@ impl AzblobCore {
req = req.header(http::header::RANGE, range.to_header());
}

if let Some(etag) = if_none_match {
req = req.header(IF_NONE_MATCH, etag);
}

let mut req = req
.body(AsyncBody::Empty)
.map_err(new_request_build_error)?;
Expand Down Expand Up @@ -172,6 +178,7 @@ impl AzblobCore {
pub async fn azblob_get_blob_properties(
&self,
path: &str,
if_none_match: Option<&str>,
) -> Result<Response<IncomingAsyncBody>> {
let p = build_abs_path(&self.root, path);

Expand All @@ -182,7 +189,11 @@ impl AzblobCore {
percent_encode_path(&p)
);

let req = Request::head(&url);
let mut req = Request::head(&url);

if let Some(etag) = if_none_match {
req = req.header(IF_NONE_MATCH, etag);
}

let mut req = req
.body(AsyncBody::Empty)
Expand Down