[PR #803] [MERGED] Handle offset-from-end ranges and make range handling more robust #932

Closed
opened 2026-03-03 12:32:17 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fsouza/fake-gcs-server/pull/803
Author: @dnerdy
Created: 6/1/2022
Status: Merged
Merged: 6/4/2022
Merged by: @fsouza

Base: mainHead: range-updates


📝 Commits (6)

  • 0aeec46 Handle offset-from-end ranges and make range handling more robust
  • 5f79e4f Remove underscore prefix from parseRange function
  • 7aa1e43 Reformat comment
  • e3fd350 Fix off by one error and add corresponding test
  • 1f4877d Remove unused length variable in test
  • 7f36cee Apply one nit from code review

📊 Changes

2 files changed (+156 additions, -40 deletions)

View changed files

📝 fakestorage/object.go (+111 -27)
📝 fakestorage/object_test.go (+45 -13)

📄 Description

This PR adds support for offset-from-end ranges. An offset-from-end
range header looks like "Range: bytes=-10". This returns content
starting 10 bytes from the end of the content to the end of the content.

The PR also updates other range responses to align with the real GCS
server. Specifically, the range handling code now detects when the start
of range is beyond the content bounds and returns a 416 response. Most
other invalid ranges are ignored, except for a few cases where bounds
are automatically adjusted.

All of the cases were verified against the GCS server using requests
like:

curl -D - https://storage.googleapis.com/marksandstrom-test/test.txt -H"Range: bytes=0-4"

Fixes #536.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fsouza/fake-gcs-server/pull/803 **Author:** [@dnerdy](https://github.com/dnerdy) **Created:** 6/1/2022 **Status:** ✅ Merged **Merged:** 6/4/2022 **Merged by:** [@fsouza](https://github.com/fsouza) **Base:** `main` ← **Head:** `range-updates` --- ### 📝 Commits (6) - [`0aeec46`](https://github.com/fsouza/fake-gcs-server/commit/0aeec463cfa010d4f6f103a769f18e2aca9705e0) Handle offset-from-end ranges and make range handling more robust - [`5f79e4f`](https://github.com/fsouza/fake-gcs-server/commit/5f79e4f4caec659de1af9063490480c0f79bd56d) Remove underscore prefix from parseRange function - [`7aa1e43`](https://github.com/fsouza/fake-gcs-server/commit/7aa1e431101fac93e10c44eea875b9f4520a0f43) Reformat comment - [`e3fd350`](https://github.com/fsouza/fake-gcs-server/commit/e3fd35087c0cdb168399176ee60ccfb8906942a1) Fix off by one error and add corresponding test - [`1f4877d`](https://github.com/fsouza/fake-gcs-server/commit/1f4877d0bb5f1200ed2fa2045a852a8b70a5cd8c) Remove unused length variable in test - [`7f36cee`](https://github.com/fsouza/fake-gcs-server/commit/7f36cee22cb008c3d25a7119b6b464d76ecbd8f3) Apply one nit from code review ### 📊 Changes **2 files changed** (+156 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `fakestorage/object.go` (+111 -27) 📝 `fakestorage/object_test.go` (+45 -13) </details> ### 📄 Description This PR adds support for offset-from-end ranges. An offset-from-end range header looks like "Range: bytes=-10". This returns content starting 10 bytes from the end of the content to the end of the content. The PR also updates other range responses to align with the real GCS server. Specifically, the range handling code now detects when the start of range is beyond the content bounds and returns a 416 response. Most other invalid ranges are ignored, except for a few cases where bounds are automatically adjusted. All of the cases were verified against the GCS server using requests like: ``` curl -D - https://storage.googleapis.com/marksandstrom-test/test.txt -H"Range: bytes=0-4" ``` Fixes #536. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-03 12:32:17 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#932
No description provided.