abersheeran / baize

Powerful and exquisite WSGI/ASGI framework/toolkit.
https://baize.aber.sh
Apache License 2.0
83 stars 3 forks source link

Issue: Incorrect behavior for Range header: failing on valid range #49

Closed trafficone closed 2 years ago

trafficone commented 2 years ago

The current implementation of handling the range header is incorrect. When a client requests data that exceeds the file size, the response is generating a 416 error.[1] The range header should not fail on a range that exceeds the representation data.

If the last-byte-pos value is absent, or if the value is greater than or equal to the current length of the representation data, the byte range is interpreted as the remainder of the representation (i.e., the server replaces the value of last-byte-pos with a value that is one less than the current length of the selected representation).[2]

The implementation should also support multiple ranges, but that isn't as pressing of an issue to me right now.

I'll respond to this with a PR once I've finished the change.

1

2

trafficone commented 2 years ago

Correction: the response supports multiple ranges. The issue was with negative ranges. Range: 0-10, 20-40 OK Range: 0-10, -500

abersheeran commented 2 years ago

Oh, this was my oversight.

trafficone commented 2 years ago

No worries, the fix seems to have been pretty straightforward. Let me know if you have any questions.

PR is #50