Skip to content
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

Refactor Range header parsing into a separate function and fix handling of zero-sized files #2482

Merged
merged 1 commit into from Oct 26, 2020

Conversation

s-ludwig
Copy link
Member

@s-ludwig s-ludwig commented Oct 14, 2020

Changes the internal representation of a range to be end-exclusive (consistent with D slices) to avoid unsigned integer wrap-around for zero sized files.

See #2481 (comment).

…ng of zero-sized files.

Changes the internal representation of a range to be end-exclusive (consistent with D slices) to avoid unsigned integer wrap-around for zero sized files.

See #2481.
unittest {
auto res = createTestHTTPServerResponse();
assertThrown(parseRangeHeader("bytes=2-1", 10, res));
assertThrown(parseRangeHeader("bytes=10-10", 10, res));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is a valid range (10-10 would simply mean, just the one byte at index 10) and thus should not throw.

See 2.1 in the RFC which only says:

   A byte-range-spec is invalid if the last-byte-pos value is present
   and less than the first-byte-pos.

plus it's actually used as an example here:

   o  The first and last bytes only (bytes 0 and 9999):
        bytes=0-0,-1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, but index 10 is outside of 10 bytes isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do you mean that it should get moved into the range as 9-9?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry you are right about that, I wasn't looking at the size there

@s-ludwig s-ludwig merged commit 70b50fd into master Oct 26, 2020
@s-ludwig s-ludwig deleted the range_header_parse_refactor branch October 26, 2020 18:58
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.

None yet

2 participants