Skip to content

fix: correctly parse suffix-byte-range in HTTP Range header#51

Open
GXbSUtze2j8b wants to merge 1 commit intowindoze95:mainfrom
GXbSUtze2j8b:fix/suffix-byte-range
Open

fix: correctly parse suffix-byte-range in HTTP Range header#51
GXbSUtze2j8b wants to merge 1 commit intowindoze95:mainfrom
GXbSUtze2j8b:fix/suffix-byte-range

Conversation

@GXbSUtze2j8b
Copy link
Copy Markdown

Fix: suffix-byte-range parsing in build_range_response

Bug: When client sends bytes=-500 (last 500 bytes), code set start=0 and returned bytes 0-500 instead of the last 500 bytes.

Root cause: Suffix-byte-range format bytes=-500 produces parts=['', '500']. The empty parts[0] was treated as "start from 0".

Fix: Added explicit check for empty parts[0] with non-empty parts[1]:

if not parts[0] and len(parts) > 1 and parts[1]:
    start = max(0, file_size - int(parts[1]))
    end = file_size - 1

Ref: #29

When client sends 'bytes=-500' (last 500 bytes), the old code set
start=0 and returned the first 501 bytes instead of the last 500.

Added explicit check for empty parts[0] with a non-empty parts[1]
(suffix-byte-range syntax) and calculate start from end of file.

Ref: windoze95#29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant