diff --git a/core/src/services/wasabi/backend.rs b/core/src/services/wasabi/backend.rs index dcb91f2eabd..a7a41042f03 100644 --- a/core/src/services/wasabi/backend.rs +++ b/core/src/services/wasabi/backend.rs @@ -715,7 +715,7 @@ impl Accessor for WasabiBackend { async fn create_dir(&self, path: &str, _: OpCreateDir) -> Result { let mut req = self.core - .put_object_request(path, Some(0), None, None, None, AsyncBody::Empty)?; + .put_object_request(path, Some(0), &OpWrite::default(), AsyncBody::Empty)?; self.core.sign(&mut req).await?; @@ -733,10 +733,7 @@ impl Accessor for WasabiBackend { } async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> { - let resp = self - .core - .get_object(path, args.range(), args.if_none_match()) - .await?; + let resp = self.core.get_object(path, &args).await?; let status = resp.status(); @@ -814,16 +811,10 @@ impl Accessor for WasabiBackend { // We will not send this request out, just for signing. let mut req = match args.operation() { PresignOperation::Stat(v) => self.core.head_object_request(path, v)?, - PresignOperation::Read(v) => self.core.get_object_request( - path, - v.range(), - v.override_content_disposition(), - v.override_cache_control(), - v.if_none_match(), - )?, + PresignOperation::Read(v) => self.core.get_object_request(path, v)?, PresignOperation::Write(_) => { self.core - .put_object_request(path, None, None, None, None, AsyncBody::Empty)? + .put_object_request(path, None, &OpWrite::default(), AsyncBody::Empty)? } }; diff --git a/core/src/services/wasabi/core.rs b/core/src/services/wasabi/core.rs index 23506c2605f..2a44bb56447 100644 --- a/core/src/services/wasabi/core.rs +++ b/core/src/services/wasabi/core.rs @@ -231,14 +231,7 @@ impl WasabiCore { Ok(req) } - pub fn get_object_request( - &self, - path: &str, - range: BytesRange, - override_content_disposition: Option<&str>, - override_cache_control: Option<&str>, - if_none_match: Option<&str>, - ) -> Result> { + pub fn get_object_request(&self, path: &str, args: &OpRead) -> Result> { let p = build_abs_path(&self.root, path); // Construct headers to add to the request @@ -246,14 +239,14 @@ impl WasabiCore { // Add query arguments to the URL based on response overrides let mut query_args = Vec::new(); - if let Some(override_content_disposition) = override_content_disposition { + if let Some(override_content_disposition) = args.override_content_disposition() { query_args.push(format!( "{}={}", constants::RESPONSE_CONTENT_DISPOSITION, percent_encode_path(override_content_disposition) )) } - if let Some(override_cache_control) = override_cache_control { + if let Some(override_cache_control) = args.override_cache_control() { query_args.push(format!( "{}={}", constants::RESPONSE_CACHE_CONTROL, @@ -266,11 +259,12 @@ impl WasabiCore { let mut req = Request::get(&url); + let range = args.range(); if !range.is_full() { req = req.header(http::header::RANGE, range.to_header()); } - if let Some(if_none_match) = if_none_match { + if let Some(if_none_match) = args.if_none_match() { req = req.header(http::header::IF_NONE_MATCH, if_none_match); } @@ -288,10 +282,9 @@ impl WasabiCore { pub async fn get_object( &self, path: &str, - range: BytesRange, - if_none_match: Option<&str>, + args: &OpRead, ) -> Result> { - let mut req = self.get_object_request(path, range, None, None, if_none_match)?; + let mut req = self.get_object_request(path, args)?; self.sign(&mut req).await?; @@ -302,9 +295,7 @@ impl WasabiCore { &self, path: &str, size: Option, - content_type: Option<&str>, - content_disposition: Option<&str>, - cache_control: Option<&str>, + args: &OpWrite, body: AsyncBody, ) -> Result> { let p = build_abs_path(&self.root, path); @@ -317,15 +308,15 @@ impl WasabiCore { req = req.header(CONTENT_LENGTH, size) } - if let Some(mime) = content_type { + if let Some(mime) = args.content_type() { req = req.header(CONTENT_TYPE, mime) } - if let Some(pos) = content_disposition { + if let Some(pos) = args.content_disposition() { req = req.header(CONTENT_DISPOSITION, pos) } - if let Some(cache_control) = cache_control { + if let Some(cache_control) = args.cache_control() { req = req.header(CACHE_CONTROL, cache_control) } @@ -471,9 +462,7 @@ impl WasabiCore { pub async fn initiate_multipart_upload( &self, path: &str, - content_type: Option<&str>, - content_disposition: Option<&str>, - cache_control: Option<&str>, + args: &OpWrite, ) -> Result> { let p = build_abs_path(&self.root, path); @@ -481,15 +470,15 @@ impl WasabiCore { let mut req = Request::post(&url); - if let Some(mime) = content_type { + if let Some(mime) = args.content_type() { req = req.header(CONTENT_TYPE, mime) } - if let Some(content_disposition) = content_disposition { + if let Some(content_disposition) = args.content_disposition() { req = req.header(CONTENT_DISPOSITION, content_disposition) } - if let Some(cache_control) = cache_control { + if let Some(cache_control) = args.cache_control() { req = req.header(CACHE_CONTROL, cache_control) } @@ -638,19 +627,10 @@ impl WasabiCore { &self, path: &str, size: Option, - content_type: Option<&str>, - content_disposition: Option<&str>, - cache_control: Option<&str>, + args: &OpWrite, body: AsyncBody, ) -> Result> { - let mut req = self.put_object_request( - path, - size, - content_type, - content_disposition, - cache_control, - body, - )?; + let mut req = self.put_object_request(path, size, args, body)?; self.sign(&mut req).await?; diff --git a/core/src/services/wasabi/writer.rs b/core/src/services/wasabi/writer.rs index cd76bf82c86..50fc8ff4fa6 100644 --- a/core/src/services/wasabi/writer.rs +++ b/core/src/services/wasabi/writer.rs @@ -49,9 +49,7 @@ impl oio::OneShotWrite for WasabiWriter { .put_object( &self.path, Some(bs.len()), - self.op.content_type(), - self.op.content_disposition(), - self.op.cache_control(), + &self.op, AsyncBody::ChunkedBytes(bs), ) .await?;