-
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Initial support for HTTP range requests #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lcian
wants to merge
46
commits into
main
Choose a base branch
from
lcian/feat/range-requests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
3cbf44e
feat: Support HTTP Range requests for single-object GETs
lcian e1fa227
improve
lcian d0fbeb6
improve
lcian f01d018
fix: Case-insensitive range unit matching and multi-range fallback
lcian f209283
fix: Harden Content-Length handling for edge cases
lcian 1c5f6cb
improve
lcian e8dd7f7
improve
lcian 4a2da3d
refactor: Simplify range request code and consolidate tests
lcian d12a378
fix: Update new tiered.rs tests for range request API changes
lcian a379844
Merge branch 'main' into lcian/feat/range-requests
lcian d03594c
improve
lcian a1c11fd
improve
lcian 2762e5b
fix(range): Reject bytes=-0 as invalid and use Content-Range total fo…
lcian 1f6caf0
improve
lcian 02743ad
improve
lcian 7d629c8
improve
lcian 3fb6975
improve range types
lcian 4025c2a
improve range types a bit more
lcian 676cf89
improve endpoint
lcian 7f65312
improve endpoint
lcian b47fb8c
implement in inmemory backend too
lcian dab4e62
improve
lcian 94e432b
improve localfs
lcian 9ce1aea
improve gcs
lcian 6abeae8
improve gcs
lcian 0ee7263
improve
lcian 367aa2f
improve
lcian fdeb846
s3 like gcs
lcian cedf351
improve
lcian e707a5c
improve
lcian 83a1899
improve s3
lcian 61e7cec
fix
lcian ee6fa4a
fix
lcian 8d40bb4
add a test
lcian a47e329
fix
lcian 5eb797c
add tests
lcian 302b1c4
reject invalid bounds
lcian 0e21c59
improve
lcian 20034e1
improve
lcian 271d62c
clippy
lcian aaa8221
improve
lcian 0aa575c
improve
lcian 04d1b78
move range header parsing to its own extractor
lcian c0939f7
fmt
lcian 3ae2f45
improve
lcian 8f63a33
improve
lcian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //! Axum extractor for range requests. | ||
|
|
||
| use axum::extract::FromRequestParts; | ||
| use http::request::Parts; | ||
| use objectstore_types::range::{ByteRange, RangeError}; | ||
|
|
||
| use crate::{endpoints::common::ApiError, state::ServiceState}; | ||
|
|
||
| /// Extractor that parses the `Range` request header into an optional [`ByteRange`]. | ||
| #[derive(Debug, Clone)] | ||
| pub struct OptionalByteRange(pub Option<ByteRange>); | ||
|
|
||
| impl FromRequestParts<ServiceState> for OptionalByteRange { | ||
| type Rejection = ApiError; | ||
|
|
||
| async fn from_request_parts( | ||
| parts: &mut Parts, | ||
| _state: &ServiceState, | ||
| ) -> Result<Self, Self::Rejection> { | ||
| let headers = &parts.headers; | ||
| let Some(range) = headers.get(http::header::RANGE) else { | ||
| return Ok(Self(None)); | ||
| }; | ||
| let range = range | ||
| .to_str() | ||
| .map_err(|_| ApiError::Client("invalid Range header".into()))?; | ||
|
|
||
| match range.parse::<ByteRange>() { | ||
| Ok(range) => Ok(Self(Some(range))), | ||
| // Per RFC 9110: | ||
| // > A server that supports range requests MAY ignore or reject a Range header | ||
| // field that contains an invalid ranges-specifier [...] | ||
| // | ||
| // If the client wants multiple ranges, fall back to returning the whole object. | ||
| // We might support multiple ranges in the future, so log a warning to let us know | ||
| // clients are trying to do this. | ||
| Err(RangeError::MultiRange) => { | ||
| objectstore_log::warn!( | ||
| "received range request with multiple range specifiers, ignoring" | ||
| ); | ||
| Ok(Self(None)) | ||
| } | ||
| // The client requested an invalid unit or sent a malformed header. | ||
| // We could fall back, but better fail hard and let them know they sent something | ||
| // invalid. | ||
| Err(err) => Err(ApiError::Client(format!("invalid Range header: {err}"))), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| pub mod batch; | ||
| pub mod body; | ||
| pub mod byte_range; | ||
| pub mod downstream_service; | ||
| mod id; | ||
| mod service; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.