Skip to content

Commit

Permalink
Error if Remote Ignores HTTP Range Header (apache#4841)
Browse files Browse the repository at this point in the history
* fix: abort http:get on !206 when issuing a range request

* add some comments

* pr feedback

* Update object_store/src/http/client.rs

Co-authored-by: Raphael Taylor-Davies <[email protected]>

---------

Co-authored-by: Raphael Taylor-Davies <[email protected]>
  • Loading branch information
2 people authored and Ryan Aston committed Nov 6, 2023
1 parent 1b2238c commit 1030493
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions object_store/src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ enum Error {
#[snafu(display("Request error: {}", source))]
Reqwest { source: reqwest::Error },

#[snafu(display("Range request not supported by {}", href))]
RangeNotSupported { href: String },

#[snafu(display("Error decoding PROPFIND response: {}", source))]
InvalidPropFind { source: quick_xml::de::DeError },

Expand Down Expand Up @@ -238,8 +241,9 @@ impl Client {
pub async fn get(&self, location: &Path, options: GetOptions) -> Result<Response> {
let url = self.path_url(location);
let builder = self.client.get(url);
let has_range = options.range.is_some();

builder
let res = builder
.with_get_options(options)
.send_retry(&self.retry_config)
.await
Expand All @@ -252,7 +256,19 @@ impl Client {
}
}
_ => Error::Request { source }.into(),
})
})?;

// We expect a 206 Partial Content response if a range was requested
// a 200 OK response would indicate the server did not fulfill the request
if has_range && res.status() != StatusCode::PARTIAL_CONTENT {
return Err(crate::Error::NotSupported {
source: Box::new(Error::RangeNotSupported {
href: location.to_string(),
}),
});
}

Ok(res)
}

pub async fn copy(&self, from: &Path, to: &Path, overwrite: bool) -> Result<()> {
Expand Down

0 comments on commit 1030493

Please sign in to comment.