mirror of
https://github.com/fsouza/fake-gcs-server.git
synced 2026-04-25 13:45:52 +03:00
[PR #2056] [fix] respect content-range header in resumable upload #2054
Labels
No labels
bug
compatibility-issue
docker
documentation
enhancement
help wanted
needs information
pull-request
question
stale
unfortunate
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/fake-gcs-server#2054
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/fsouza/fake-gcs-server/pull/2056
Author: @JornEngelbart
Created: 10/31/2025
Status: 🔄 Open
Base:
main← Head:respect-content-range-header-in-resumable-upload📝 Commits (1)
1f3322e[fix] respect content-range header in resumable upload📊 Changes
2 files changed (+257 additions, -13 deletions)
View changed files
📝
fakestorage/upload.go(+54 -13)📝
fakestorage/upload_test.go(+203 -0)📄 Description
Fix Content-Range header handling in resumable uploads
Problem
The resumable upload implementation was not correctly handling the
Content-Rangeheader when uploading chunks. The code was simply appending all chunks sequentially (obj.Content = append(obj.Content, content...)), which caused incorrect behavior when:This resulted in:
Solution
The fix properly parses and respects the
Content-Rangeheader to place content at the exact byte positions specified:Key Changes
Parse Content-Range before appending: The code now parses the
Content-Rangeheader first to determine where content should be placedPlace content at specified positions: Instead of appending, content is copied to the exact byte range specified:
Handle overlapping ranges: When the same range is uploaded multiple times, the content correctly overwrites the previous content at those positions
Extend buffer as needed: The buffer is automatically extended with zero-filled bytes when a range requires a larger buffer size
Validate content length: Added validation to ensure the actual content length matches the Content-Range header specification
Example Scenario
Previously, if a client sent:
Content-Range: bytes 0-262143/377464(262144 bytes)Content-Range: bytes 1-262144/377464(262144 bytes, overlapping)Content-Range: bytes 1-377463/377464(377463 bytes, overlapping)The old code would append all chunks sequentially, resulting in an incorrect file.
The new code correctly:
Testing
Added comprehensive test coverage in
TestResumableUploadWithContentRangethat verifies:Impact
This fix ensures that fake-gcs-server correctly handles resumable uploads with Content-Range headers, making it compatible with clients that:
The fix is backward compatible and maintains the existing behavior for uploads without Content-Range headers (falls back to append behavior).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.