aboutsummaryrefslogtreecommitdiff
path: root/src/api/s3_get.rs
diff options
context:
space:
mode:
authortrinity-1686a <trinity.pointard@gmail.com>2021-11-29 11:52:42 +0100
committerAlex <alex@adnab.me>2021-11-29 11:52:42 +0100
commit7f26ed55cdad4a67300447cf92bf8e4975a5c978 (patch)
tree4b19ae34f53351bc4850a6c3ab2c04dfe87f10d3 /src/api/s3_get.rs
parent8811bb08e6d5eb024bacdfbb20d039c6b696e1a6 (diff)
downloadgarage-7f26ed55cdad4a67300447cf92bf8e4975a5c978.tar.gz
garage-7f26ed55cdad4a67300447cf92bf8e4975a5c978.zip
Improved handling of HTTP ranges
- correct HTTP code when range syntax is invalid (fix #140) - when multiple ranges are given, simply ignore and send whole file Co-authored-by: Trinity Pointard <trinity.pointard@gmail.com> Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/157 Reviewed-by: Alex <alex@adnab.me> Co-authored-by: trinity-1686a <trinity.pointard@gmail.com> Co-committed-by: trinity-1686a <trinity.pointard@gmail.com>
Diffstat (limited to 'src/api/s3_get.rs')
-rw-r--r--src/api/s3_get.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/api/s3_get.rs b/src/api/s3_get.rs
index 10d6591f..428bbf34 100644
--- a/src/api/s3_get.rs
+++ b/src/api/s3_get.rs
@@ -156,11 +156,12 @@ pub async fn handle_get(
let range = match req.headers().get("range") {
Some(range) => {
let range_str = range.to_str()?;
- let mut ranges = http_range::HttpRange::parse(range_str, last_v_meta.size)?;
+ let mut ranges = http_range::HttpRange::parse(range_str, last_v_meta.size)
+ .map_err(|e| (e, last_v_meta.size))?;
if ranges.len() > 1 {
- return Err(Error::BadRequest(
- "Multiple ranges not supported".to_string(),
- ));
+ // garage does not support multi-range requests yet, so we respond with the entire
+ // object when multiple ranges are requested
+ None
} else {
ranges.pop()
}
@@ -235,10 +236,6 @@ async fn handle_get_range(
begin: u64,
end: u64,
) -> Result<Response<Body>, Error> {
- if end > version_meta.size {
- return Err(Error::BadRequest("Range not included in file".to_string()));
- }
-
let resp_builder = object_headers(version, version_meta)
.header("Content-Length", format!("{}", end - begin))
.header(