Skip to content

Commit

Permalink
Fix: GetObject range request
Browse files Browse the repository at this point in the history
  • Loading branch information
nomick committed Jan 21, 2024
1 parent 400f075 commit 59dab7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions crates/s3s-fs/src/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion crates/s3s/src/dto/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 59dab7f

Please sign in to comment.