From f22ecb60a8e1848de95e1bd3104b0ceec7058f0c Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 7 Jul 2020 17:15:53 +0200 Subject: Update to Hyper 0.13.6 that accepts non-Sync streams in wrap_stream. Simplifies code and makes it possible to publish on crates.io --- src/api/s3_get.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/api/s3_get.rs') diff --git a/src/api/s3_get.rs b/src/api/s3_get.rs index 63200ca3..5f2151b5 100644 --- a/src/api/s3_get.rs +++ b/src/api/s3_get.rs @@ -12,8 +12,6 @@ use garage_table::EmptyKey; use garage_model::garage::Garage; use garage_model::object_table::*; -use crate::http_util::*; - fn object_headers(version: &ObjectVersion) -> http::response::Builder { let date = UNIX_EPOCH + Duration::from_millis(version.timestamp); let date_str = httpdate::fmt_http_date(date); @@ -29,7 +27,7 @@ pub async fn handle_head( garage: Arc, bucket: &str, key: &str, -) -> Result, Error> { +) -> Result, Error> { let object = match garage .object_table .get(&bucket.to_string(), &key.to_string()) @@ -50,7 +48,7 @@ pub async fn handle_head( None => return Err(Error::NotFound), }; - let body: BodyType = Box::new(BytesBody::from(vec![])); + let body: Body = Body::from(vec![]); let response = object_headers(&version) .status(StatusCode::OK) .body(body) @@ -63,7 +61,7 @@ pub async fn handle_get( req: &Request, bucket: &str, key: &str, -) -> Result, Error> { +) -> Result, Error> { let object = match garage .object_table .get(&bucket.to_string(), &key.to_string()) @@ -111,7 +109,7 @@ pub async fn handle_get( ))), ObjectVersionData::DeleteMarker => Err(Error::NotFound), ObjectVersionData::Inline(bytes) => { - let body: BodyType = Box::new(BytesBody::from(bytes.to_vec())); + let body: Body = Body::from(bytes.to_vec()); Ok(resp_builder.body(body)?) } ObjectVersionData::FirstBlock(first_block_hash) => { @@ -147,7 +145,8 @@ pub async fn handle_get( } }) .buffered(2); - let body: BodyType = Box::new(StreamBody::new(Box::pin(body_stream))); + //let body: Body = Box::new(StreamBody::new(Box::pin(body_stream))); + let body = hyper::body::Body::wrap_stream(body_stream); Ok(resp_builder.body(body)?) } } @@ -158,7 +157,7 @@ pub async fn handle_get_range( version: &ObjectVersion, begin: u64, end: u64, -) -> Result, Error> { +) -> Result, Error> { if end > version.size { return Err(Error::BadRequest(format!("Range not included in file"))); } @@ -177,9 +176,9 @@ pub async fn handle_get_range( ObjectVersionData::DeleteMarker => Err(Error::NotFound), ObjectVersionData::Inline(bytes) => { if end as usize <= bytes.len() { - let body: BodyType = Box::new(BytesBody::from( + let body: Body = Body::from( bytes[begin as usize..end as usize].to_vec(), - )); + ); Ok(resp_builder.body(body)?) } else { Err(Error::Message(format!("Internal error: requested range not present in inline bytes when it should have been"))) @@ -214,13 +213,14 @@ pub async fn handle_get_range( } else { end - block.offset }; - Ok(Bytes::from( + Result::::Ok(Bytes::from( data[start_in_block as usize..end_in_block as usize].to_vec(), )) } }) .buffered(2); - let body: BodyType = Box::new(StreamBody::new(Box::pin(body_stream))); + //let body: Body = Box::new(StreamBody::new(Box::pin(body_stream))); + let body = hyper::body::Body::wrap_stream(body_stream); Ok(resp_builder.body(body)?) } } -- cgit v1.2.3