diff options
author | Quentin <quentin@deuxfleurs.fr> | 2020-12-05 18:57:22 +0100 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2020-12-05 18:57:22 +0100 |
commit | bd7e3d1bd1c4df4f2848e0f8c49878dacb330b50 (patch) | |
tree | 2d78d58473f09577aa57b23988877a3dcb39121c | |
parent | 9f46fb699a68c2d8b721b0b1d0e3419a830a4052 (diff) | |
download | garage-bd7e3d1bd1c4df4f2848e0f8c49878dacb330b50.tar.gz garage-bd7e3d1bd1c4df4f2848e0f8c49878dacb330b50.zip |
Fix Content-Lengthbug/content-range
-rw-r--r-- | src/api/s3_get.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/api/s3_get.rs b/src/api/s3_get.rs index a5e7b342..a52222a0 100644 --- a/src/api/s3_get.rs +++ b/src/api/s3_get.rs @@ -15,6 +15,7 @@ use crate::error::*; fn object_headers( version: &ObjectVersion, version_meta: &ObjectVersionMeta, + partial_size: Option<u64> ) -> http::response::Builder { let date = UNIX_EPOCH + Duration::from_millis(version.timestamp); let date_str = httpdate::fmt_http_date(date); @@ -24,7 +25,7 @@ fn object_headers( "Content-Type", version_meta.headers.content_type.to_string(), ) - .header("Content-Length", format!("{}", version_meta.size)) + .header("Content-Length", format!("{}", partial_size.unwrap_or(version_meta.size))) .header("ETag", version_meta.etag.to_string()) .header("Last-Modified", date_str) .header("Accept-Ranges", format!("bytes")); @@ -62,7 +63,7 @@ pub async fn handle_head( }; let body: Body = Body::from(vec![]); - let response = object_headers(&version, version_meta) + let response = object_headers(&version, version_meta, None) .status(StatusCode::OK) .body(body) .unwrap(); @@ -123,7 +124,7 @@ pub async fn handle_get( .await; } - let resp_builder = object_headers(&last_v, last_v_meta).status(StatusCode::OK); + let resp_builder = object_headers(&last_v, last_v_meta, None).status(StatusCode::OK); match &last_v_data { ObjectVersionData::DeleteMarker => unreachable!(), @@ -180,7 +181,7 @@ pub async fn handle_get_range( return Err(Error::BadRequest(format!("Range not included in file"))); } - let resp_builder = object_headers(version, version_meta) + let resp_builder = object_headers(version, version_meta, Some(end - begin)) .header( "Content-Range", format!("bytes {}-{}/{}", begin, end - 1, version_meta.size), |