diff --git a/core/src/services/http/backend.rs b/core/src/services/http/backend.rs index 37048748f921..af50631cca47 100644 --- a/core/src/services/http/backend.rs +++ b/core/src/services/http/backend.rs @@ -232,9 +232,7 @@ impl Accessor for HttpBackend { } async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> { - let resp = self - .http_get(path, args.range(), args.if_match(), args.if_none_match()) - .await?; + let resp = self.http_get(path, &args).await?; let status = resp.status(); @@ -253,9 +251,7 @@ impl Accessor for HttpBackend { return Ok(RpStat::new(Metadata::new(EntryMode::DIR))); } - let resp = self - .http_head(path, args.if_match(), args.if_none_match()) - .await?; + let resp = self.http_head(path, &args).await?; let status = resp.status(); @@ -272,24 +268,18 @@ impl Accessor for HttpBackend { } impl HttpBackend { - async fn http_get( - &self, - path: &str, - range: BytesRange, - if_match: Option<&str>, - if_none_match: Option<&str>, - ) -> Result> { + async fn http_get(&self, path: &str, args: &OpRead) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&p)); let mut req = Request::get(&url); - if let Some(if_match) = if_match { + if let Some(if_match) = args.if_match() { req = req.header(IF_MATCH, if_match); } - if let Some(if_none_match) = if_none_match { + if let Some(if_none_match) = args.if_none_match() { req = req.header(IF_NONE_MATCH, if_none_match); } @@ -297,8 +287,8 @@ impl HttpBackend { req = req.header(header::AUTHORIZATION, auth.clone()) } - if !range.is_full() { - req = req.header(header::RANGE, range.to_header()); + if !args.range().is_full() { + req = req.header(header::RANGE, args.range().to_header()); } let req = req @@ -308,23 +298,18 @@ impl HttpBackend { self.client.send(req).await } - async fn http_head( - &self, - path: &str, - if_match: Option<&str>, - if_none_match: Option<&str>, - ) -> Result> { + async fn http_head(&self, path: &str, args: &OpStat) -> Result> { let p = build_rooted_abs_path(&self.root, path); let url = format!("{}{}", self.endpoint, percent_encode_path(&p)); let mut req = Request::head(&url); - if let Some(if_match) = if_match { + if let Some(if_match) = args.if_match() { req = req.header(IF_MATCH, if_match); } - if let Some(if_none_match) = if_none_match { + if let Some(if_none_match) = args.if_none_match() { req = req.header(IF_NONE_MATCH, if_none_match); }