Skip to content
Merged
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
35 changes: 10 additions & 25 deletions core/src/services/http/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -272,33 +268,27 @@ 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<Response<IncomingAsyncBody>> {
async fn http_get(&self, path: &str, args: &OpRead) -> Result<Response<IncomingAsyncBody>> {
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);
}

if let Some(auth) = &self.authorization {
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
Expand All @@ -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<Response<IncomingAsyncBody>> {
async fn http_head(&self, path: &str, args: &OpStat) -> Result<Response<IncomingAsyncBody>> {
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);
}

Expand Down