Add proper partial content response handling #370
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.
This change fixes HTTP range request handling issues in the piped-proxy, ensuring proper partial content responses and Content-Range headers are returned when clients request specific byte ranges from video streams. This will fix playback issues on LibreTube (libre-tube/LibreTube#7463)
Problem Solved
The proxy was not properly handling HTTP range requests, causing several issues:
Changes Made
New Range Request Handling Infrastructure
Added new structs and functions in
src/main.rs
:parse_range()
: Parses range strings (e.g., "0-1023") into structured RangeRequest objects with proper bounds checkinghandle_range_response_correction()
: Main correction logic that detects range requests and converts 200 OK responses to 206 Partial Contentapply_range_headers()
: Applies proper HTTP headers for partial content responsesCore Fixes
handle_range_response_correction()
after response building to fix status codes and headersTechnical Details
Content-Range: bytes start-end/total
headersBenefits
Testing
The changes include comprehensive error handling and validation:
This fix ensures the proxy correctly handles partial content requests, improving compatibility with media players and enabling features like video seeking and resumable downloads.
LLM's help were taken to solve this issue 😅