S3:head_object() now returns the PartsCount-header (#5438)

This commit is contained in:
Bert Blommers 2022-08-31 18:34:56 +00:00 committed by GitHub
parent d145471b3f
commit 53efd628c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View File

@ -1579,6 +1579,12 @@ class S3Response(BaseResponse):
if if_none_match and key.etag == if_none_match:
return 304, response_headers, "Not Modified"
if part_number:
full_key = self.backend.head_object(bucket_name, key_name, version_id)
if full_key.multipart:
mp_part_count = str(len(full_key.multipart.partlist))
response_headers["x-amz-mp-parts-count"] = mp_part_count
return 200, response_headers, ""
else:
return 404, response_headers, ""

View File

@ -969,3 +969,43 @@ def test_generate_presigned_url_on_multipart_upload_without_acl():
)
res = requests.get(url)
res.status_code.should.equal(200)
@mock_s3
@reduced_min_part_size
def test_head_object_returns_part_count():
bucket = "telstra-energy-test"
key = "test-single-multi-part"
client = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
client.create_bucket(Bucket=bucket)
mp_id = client.create_multipart_upload(Bucket=bucket, Key=key)["UploadId"]
num_parts = 2
parts = []
for p in range(1, num_parts + 1):
response = client.upload_part(
Body=b"x" * (REDUCED_PART_SIZE + p),
Bucket=bucket,
Key=key,
PartNumber=p,
UploadId=mp_id,
)
parts.append({"ETag": response["ETag"], "PartNumber": p})
client.complete_multipart_upload(
Bucket=bucket,
Key=key,
MultipartUpload={"Parts": parts},
UploadId=mp_id,
)
resp = client.head_object(Bucket=bucket, Key=key, PartNumber=1)
resp.should.have.key("PartsCount").equals(num_parts)
# Header is not returned when we do not pass PartNumber
resp = client.head_object(Bucket=bucket, Key=key)
resp.shouldnt.have.key("PartsCount")