aboutsummaryrefslogtreecommitdiff
path: root/src/api/api_server.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-05-04 13:09:23 +0000
committerAlex Auvolat <alex@adnab.me>2020-05-04 13:09:23 +0000
commitb46a7788d160f0cec285d77664e09760d25e2144 (patch)
tree938c28c24390834218fee2320e6d58e8096eb7a0 /src/api/api_server.rs
parent16fbb32fd3ac00f76937c2799d01e7607449fa94 (diff)
downloadgarage-b46a7788d160f0cec285d77664e09760d25e2144.tar.gz
garage-b46a7788d160f0cec285d77664e09760d25e2144.zip
Implement HTTP ranges in get
Diffstat (limited to 'src/api/api_server.rs')
-rw-r--r--src/api/api_server.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/api/api_server.rs b/src/api/api_server.rs
index 913ff0af..32506ccd 100644
--- a/src/api/api_server.rs
+++ b/src/api/api_server.rs
@@ -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"))),
}
}
}