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/if_match for gcs #2039

Merged
merged 1 commit 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
5 changes: 4 additions & 1 deletion core/src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,10 @@ impl Accessor for GcsBackend {
}

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

if resp.status().is_success() {
let meta = parse_into_metadata(path, resp.headers())?;
Expand Down
21 changes: 16 additions & 5 deletions core/src/services/gcs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
// specific language governing permissions and limitations
// under the License.

use std::fmt::Debug;
use std::fmt::Formatter;
use std::fmt::Write;

use backon::ExponentialBuilder;
use backon::Retryable;
use bytes::{Bytes, BytesMut};
use http::header::CONTENT_TYPE;
use http::header::IF_MATCH;
use http::header::IF_NONE_MATCH;
use http::header::{CONTENT_LENGTH, CONTENT_RANGE};
use http::Request;
use http::Response;
Expand All @@ -31,6 +29,9 @@ use reqsign::GoogleCredentialLoader;
use reqsign::GoogleSigner;
use reqsign::GoogleToken;
use reqsign::GoogleTokenLoader;
use std::fmt::Debug;
use std::fmt::Formatter;
use std::fmt::Write;

use super::uri::percent_encode_path;
use crate::raw::*;
Expand Down Expand Up @@ -97,6 +98,8 @@ impl GcsCore {
&self,
path: &str,
range: BytesRange,
if_match: Option<&str>,
if_none_match: Option<&str>,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);

Expand All @@ -109,6 +112,12 @@ impl GcsCore {

let mut req = Request::get(&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);
}
if !range.is_full() {
req = req.header(http::header::RANGE, range.to_header());
}
Expand All @@ -124,8 +133,10 @@ impl GcsCore {
&self,
path: &str,
range: BytesRange,
if_match: Option<&str>,
if_none_match: Option<&str>,
) -> Result<Response<IncomingAsyncBody>> {
let mut req = self.gcs_get_object_request(path, range)?;
let mut req = self.gcs_get_object_request(path, range, if_match, if_none_match)?;

self.sign(&mut req).await?;
self.send(req).await
Expand Down