Skip to content

Commit

Permalink
Correctly handle single-byte Content-Range (#1032)
Browse files Browse the repository at this point in the history
HTTPie previously failed if it continued a download with a single byte left.
  • Loading branch information
blyxxyz authored Feb 14, 2021
1 parent e944dbd commit 84c7327
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion httpie/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def parse_content_range(content_range: str, resumed_from: int) -> int:
# last-byte-pos value, is invalid. The recipient of an invalid
# byte-content-range- spec MUST ignore it and any content
# transferred along with it."
if (first_byte_pos >= last_byte_pos
if (first_byte_pos > last_byte_pos
or (instance_length is not None
and instance_length <= last_byte_pos)):
raise ContentRangeError(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def test_Content_Range_parsing(self):
assert parse('bytes 100-199/200', 100) == 200
assert parse('bytes 100-199/*', 100) == 200

# single byte
assert parse('bytes 100-100/*', 100) == 101

# missing
pytest.raises(ContentRangeError, parse, None, 100)

Expand All @@ -45,9 +48,6 @@ def test_Content_Range_parsing(self):
# invalid byte-range-resp-spec
pytest.raises(ContentRangeError, parse, 'bytes 100-99/199', 100)

# invalid byte-range-resp-spec
pytest.raises(ContentRangeError, parse, 'bytes 100-100/*', 100)

@pytest.mark.parametrize('header, expected_filename', [
('attachment; filename=hello-WORLD_123.txt', 'hello-WORLD_123.txt'),
('attachment; filename=".hello-WORLD_123.txt"', 'hello-WORLD_123.txt'),
Expand Down

0 comments on commit 84c7327

Please sign in to comment.