From 59dab7fb040f521d16f7e16cf887d9cff61ceb0e Mon Sep 17 00:00:00 2001 From: Michael Rossberg Date: Sun, 21 Jan 2024 19:25:03 +0100 Subject: [PATCH] Fix: GetObject range request --- crates/s3s-fs/src/s3.rs | 10 +++++++--- crates/s3s/src/dto/range.rs | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/s3s-fs/src/s3.rs b/crates/s3s-fs/src/s3.rs index e16fff23..6c46e3a1 100644 --- a/crates/s3s-fs/src/s3.rs +++ b/crates/s3s-fs/src/s3.rs @@ -195,11 +195,14 @@ impl S3 for FileSystem { let last_modified = Timestamp::from(try_!(file_metadata.modified())); let file_len = file_metadata.len(); - let content_length = match input.range { - None => file_len, + let (content_length, content_range) = match input.range { + None => (file_len, None), Some(range) => { let file_range = range.check(file_len)?; - file_range.end - file_range.start + ( + file_range.end - file_range.start, + Some(format!("bytes {}-{}/{file_len}", file_range.start, file_range.end - 1)), + ) } }; let content_length_usize = try_!(usize::try_from(content_length)); @@ -232,6 +235,7 @@ impl S3 for FileSystem { let output = GetObjectOutput { body: Some(StreamingBlob::wrap(body)), content_length: content_length_i64, + content_range, last_modified: Some(last_modified), metadata: object_metadata, e_tag: Some(e_tag), diff --git a/crates/s3s/src/dto/range.rs b/crates/s3s/src/dto/range.rs index 4664980e..bb568d8f 100644 --- a/crates/s3s/src/dto/range.rs +++ b/crates/s3s/src/dto/range.rs @@ -111,7 +111,8 @@ impl Range { match *self { Range::Int { first, last } => match last { Some(last) => { - if first > last || last >= full_length { + let last = last.min(full_length - 1); + if first > last { return Err(err()); } // first <= last < full_length