Skip to content

Commit

Permalink
rohmu: fix Range header syntax for S3 implementation
Browse files Browse the repository at this point in the history
HTTP specs specify = as separator between unit and the ranges, not space
  • Loading branch information
giacomo-alzetta-aiven committed Jul 12, 2023
1 parent 2e6fee9 commit c46b0c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rohmu/object_storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def _get_object_stream(self, key: str, byte_range: Optional[tuple[int, int]]) ->
path = self.format_key_for_backend(key, remove_slash_prefix=True)
kwargs: dict[str, Any] = {}
if byte_range:
kwargs["Range"] = f"bytes {byte_range[0]}-{byte_range[1]}"
kwargs["Range"] = f"bytes={byte_range[0]}-{byte_range[1]}"
try:
# Actual usage is accounted for in
# _read_object_to_fileobj, although that omits the initial
Expand Down
18 changes: 18 additions & 0 deletions test/test_object_storage_s3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Copyright (c) 2022 Aiven, Helsinki, Finland. https://aiven.io/"""
from botocore.response import StreamingBody
from dataclasses import dataclass
from datetime import datetime
from io import BytesIO
Expand Down Expand Up @@ -115,3 +116,20 @@ def test_get_contents_to_fileobj_raises_error_on_invalid_byte_range(infra: S3Inf
fileobj_to_store_to=BytesIO(),
byte_range=(100, 10),
)


def test_get_contents_to_fileobj_passes_the_correct_range_header(infra: S3Infra) -> None:
transfer = infra.transfer
infra.s3_client.get_object.return_value = {
"Body": StreamingBody(BytesIO(b"value"), 5),
"ContentLength": 5,
"Metadata": {},
}
transfer.get_contents_to_fileobj(
key="test_key",
fileobj_to_store_to=BytesIO(),
byte_range=(10, 100),
)
infra.s3_client.get_object.assert_called_once_with(
Bucket="test-bucket", Key="test-prefix/test_key", Range="bytes=10-100"
)

0 comments on commit c46b0c7

Please sign in to comment.