From d4ae7c89aa0ba41b45720bebfe90054bc9e53df7 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 17 Jan 2022 14:20:40 -0500 Subject: [PATCH] First end-to-end immutable upload then download test passes. --- integration/test_storage_http.py | 2 +- src/allmydata/storage/http_client.py | 5 +++-- src/allmydata/storage/http_server.py | 21 ++++++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/integration/test_storage_http.py b/integration/test_storage_http.py index 66a8b2af1..0e2cf89a6 100644 --- a/integration/test_storage_http.py +++ b/integration/test_storage_http.py @@ -223,7 +223,7 @@ class ImmutableHTTPAPITests(AsyncTestCase): # We can now read: for offset, length in [(0, 100), (10, 19), (99, 0), (49, 200)]: downloaded = yield im_client.read_share_chunk( - storage_index, 1, upload_secret, offset, length + storage_index, 1, offset, length ) self.assertEqual(downloaded, expected_data[offset : offset + length]) diff --git a/src/allmydata/storage/http_client.py b/src/allmydata/storage/http_client.py index 697af91b5..b091b3ca7 100644 --- a/src/allmydata/storage/http_client.py +++ b/src/allmydata/storage/http_client.py @@ -252,12 +252,13 @@ class StorageClientImmutables(object): headers=Headers( { # The range is inclusive. - "range": ["bytes={}-{}".format(offset, offset + length)] + "range": ["bytes={}-{}".format(offset, offset + length - 1)] } ), ) if response.code == 200: - returnValue(response.content.read()) + body = yield response.content() + returnValue(body) else: raise ClientException( response.code, diff --git a/src/allmydata/storage/http_server.py b/src/allmydata/storage/http_server.py index 28367752d..50d955127 100644 --- a/src/allmydata/storage/http_server.py +++ b/src/allmydata/storage/http_server.py @@ -241,6 +241,7 @@ class HTTPServer(object): # TODO if raises ConflictingWriteError, return HTTP CONFLICT code. if finished: + bucket.close() request.setResponseCode(http.CREATED) else: request.setResponseCode(http.OK) @@ -257,8 +258,22 @@ class HTTPServer(object): ) def read_share_chunk(self, request, authorization, storage_index, share_number): """Read a chunk for an already uploaded immutable.""" - # TODO read offset and length from Range header # TODO basic checks on validity - # TODO lookup the share + storage_index = si_a2b(storage_index.encode("ascii")) + range_header = request.getHeader("range") + if range_header is None: + offset = 0 + inclusive_end = None + else: + parts = range_header.split("=")[1].split("-") + offset = int(parts[0]) # TODO make sure valid + if len(parts) > 0: + inclusive_end = int(parts[1]) # TODO make sure valid + else: + inclusive_end = None + + assert inclusive_end != None # TODO support this case + # TODO if not found, 404 - # TODO otherwise, return data from that offset + bucket = self._storage_server.get_buckets(storage_index)[share_number] + return bucket.read(offset, inclusive_end - offset + 1)