fix: correctly handle HTTP suffix-byte-range requests (bytes=-N)#36
Open
dreamcreated wants to merge 1 commit intowindoze95:mainfrom
Open
fix: correctly handle HTTP suffix-byte-range requests (bytes=-N)#36dreamcreated wants to merge 1 commit intowindoze95:mainfrom
dreamcreated wants to merge 1 commit intowindoze95:mainfrom
Conversation
When a client sends 'Range: bytes=-500' (last 500 bytes), the previous code split on '-' and got ['', '500']. Since parts[0] was empty, start was set to 0 and end to 500, returning the first 501 bytes instead of the last 500. Fix by detecting the suffix-byte-range format (empty start, non-empty end) and computing: start = max(0, file_size - N), end = file_size - 1. Fixes windoze95#29
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Fixes #29
In
app/services/media_server.py, thebuild_range_responsefunction incorrectly handles suffix-byte-range requests (e.g.bytes=-500).When a client sends
Range: bytes=-500(meaning "give me the last 500 bytes"), the old code splits on-to get["", "500"]. Becauseparts[0]is empty,startwas set to0andendto500— returning the first 501 bytes instead of the last 500.This breaks clients that seek to the end of a file or read trailing metadata (e.g. MP4 moov atoms, ID3 tags).
Fix
Add a check for the suffix-byte-range format before the normal parse:
Tests
Verified with all four cases:
bytes=-500bytes=0-1023bytes=5000-bytes=-99999