diff options
Diffstat (limited to 'src/api/s3/get.rs')
-rw-r--r-- | src/api/s3/get.rs | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/src/api/s3/get.rs b/src/api/s3/get.rs index f5d3cf11..eea3434e 100644 --- a/src/api/s3/get.rs +++ b/src/api/s3/get.rs @@ -163,7 +163,15 @@ pub async fn handle_head( key: &str, part_number: Option<u64>, ) -> Result<Response<ResBody>, Error> { - handle_head_without_ctx(ctx.garage, req, ctx.bucket_id, key, part_number).await + handle_head_without_ctx( + ctx.garage, + req, + ctx.bucket_id, + key, + StatusCode::OK, + part_number, + ) + .await } /// Handle HEAD request for website @@ -172,6 +180,7 @@ pub async fn handle_head_without_ctx( req: &Request<impl Body>, bucket_id: Uuid, key: &str, + status_code: StatusCode, part_number: Option<u64>, ) -> Result<Response<ResBody>, Error> { let object = garage @@ -272,7 +281,7 @@ pub async fn handle_head_without_ctx( checksum_mode, ) .header(CONTENT_LENGTH, format!("{}", version_meta.size)) - .status(StatusCode::OK) + .status(status_code) .body(empty_body())?) } } @@ -285,7 +294,16 @@ pub async fn handle_get( part_number: Option<u64>, overrides: GetObjectOverrides, ) -> Result<Response<ResBody>, Error> { - handle_get_without_ctx(ctx.garage, req, ctx.bucket_id, key, part_number, overrides).await + handle_get_without_ctx( + ctx.garage, + req, + ctx.bucket_id, + key, + StatusCode::OK, + part_number, + overrides, + ) + .await } /// Handle GET request @@ -294,6 +312,7 @@ pub async fn handle_get_without_ctx( req: &Request<impl Body>, bucket_id: Uuid, key: &str, + status_code: StatusCode, part_number: Option<u64>, overrides: GetObjectOverrides, ) -> Result<Response<ResBody>, Error> { @@ -329,11 +348,15 @@ pub async fn handle_get_without_ctx( let checksum_mode = checksum_mode(&req); - match (part_number, parse_range_header(req, last_v_meta.size)?) { - (Some(_), Some(_)) => Err(Error::bad_request( + match ( + part_number, + parse_range_header(req, last_v_meta.size)?, + status_code == StatusCode::OK, + ) { + (Some(_), Some(_), _) => Err(Error::bad_request( "Cannot specify both partNumber and Range header", )), - (Some(pn), None) => { + (Some(pn), None, true) => { handle_get_part( garage, last_v, @@ -346,7 +369,7 @@ pub async fn handle_get_without_ctx( ) .await } - (None, Some(range)) => { + (None, Some(range), true) => { handle_get_range( garage, last_v, @@ -360,7 +383,8 @@ pub async fn handle_get_without_ctx( ) .await } - (None, None) => { + _ => { + // either not a range, or an error request: always return the full doc handle_get_full( garage, last_v, @@ -370,6 +394,7 @@ pub async fn handle_get_without_ctx( &headers, overrides, checksum_mode, + status_code, ) .await } @@ -385,6 +410,7 @@ async fn handle_get_full( meta_inner: &ObjectVersionMetaInner, overrides: GetObjectOverrides, checksum_mode: ChecksumMode, + status_code: StatusCode, ) -> Result<Response<ResBody>, Error> { let mut resp_builder = object_headers( version, @@ -394,7 +420,7 @@ async fn handle_get_full( checksum_mode, ) .header(CONTENT_LENGTH, format!("{}", version_meta.size)) - .status(StatusCode::OK); + .status(status_code); getobject_override_headers(overrides, &mut resp_builder)?; let stream = full_object_byte_stream(garage, version, version_data, encryption); |