summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Verbeek <jan.verbeek@posteo.nl>2021-02-14 13:30:58 +0100
committerGitHub <noreply@github.com>2021-02-14 13:30:58 +0100
commit84c73270578bf80ae00f341ca35da12b7283bd19 (patch)
treefe8076a1074b96d48196bc9fdba21f1010a868c5
parente944dbd7fa467da4fba49f00253a6ea30015fba2 (diff)
Correctly handle single-byte Content-Range (#1032)
HTTPie previously failed if it continued a download with a single byte left.
-rw-r--r--httpie/downloads.py2
-rw-r--r--tests/test_downloads.py6
2 files changed, 4 insertions, 4 deletions
diff --git a/httpie/downloads.py b/httpie/downloads.py
index 4bd136b1..3c749a53 100644
--- a/httpie/downloads.py
+++ b/httpie/downloads.py
@@ -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(
diff --git a/tests/test_downloads.py b/tests/test_downloads.py
index f32043b8..969021d9 100644
--- a/tests/test_downloads.py
+++ b/tests/test_downloads.py
@@ -30,6 +30,9 @@ class TestDownloadUtils:
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)
@@ -45,9 +48,6 @@ class TestDownloadUtils:
# 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'),