Implement HTTP ranges in get

This commit is contained in:
Alex Auvolat
2020-05-04 13:09:23 +00:00
parent 16fbb32fd3
commit b46a7788d1
7 changed files with 229 additions and 99 deletions
+18 -21
View File
@@ -73,8 +73,7 @@ async fn handler_inner(
req: Request<Body>,
) -> Result<Response<BodyType>, Error> {
let path = req.uri().path().to_string();
let path = percent_encoding::percent_decode_str(&path)
.decode_utf8()?;
let path = percent_encoding::percent_decode_str(&path).decode_utf8()?;
let (bucket, key) = parse_bucket_key(&path)?;
if bucket.len() == 0 {
@@ -110,7 +109,7 @@ async fn handler_inner(
}
&Method::GET => {
// GetObject query
Ok(handle_get(garage, &bucket, &key).await?)
Ok(handle_get(garage, &req, &bucket, &key).await?)
}
&Method::PUT => {
if params.contains_key(&"partnumber".to_string())
@@ -123,8 +122,8 @@ async fn handler_inner(
} else if req.headers().contains_key("x-amz-copy-source") {
// CopyObject query
let copy_source = req.headers().get("x-amz-copy-source").unwrap().to_str()?;
let copy_source = percent_encoding::percent_decode_str(&copy_source)
.decode_utf8()?;
let copy_source =
percent_encoding::percent_decode_str(&copy_source).decode_utf8()?;
let (source_bucket, source_key) = parse_bucket_key(&copy_source)?;
if !api_key.allow_read(&source_bucket) {
return Err(Error::Forbidden(format!(
@@ -228,22 +227,20 @@ async fn handler_inner(
)
.await?)
}
&Method::POST => {
if params.contains_key(&"delete".to_string()) {
// DeleteObjects
Ok(handle_delete_objects(garage, bucket, req).await?)
} else {
println!(
"Body: {}",
std::str::from_utf8(&hyper::body::to_bytes(req.into_body()).await?)
.unwrap_or("<invalid utf8>")
);
Err(Error::BadRequest(format!("Unsupported call")))
}
}
_ => {
Err(Error::BadRequest(format!("Invalid method")))
}
&Method::POST => {
if params.contains_key(&"delete".to_string()) {
// DeleteObjects
Ok(handle_delete_objects(garage, bucket, req).await?)
} else {
println!(
"Body: {}",
std::str::from_utf8(&hyper::body::to_bytes(req.into_body()).await?)
.unwrap_or("<invalid utf8>")
);
Err(Error::BadRequest(format!("Unsupported call")))
}
}
_ => Err(Error::BadRequest(format!("Invalid method"))),
}
}
}