getmoto / moto

A library that allows you to easily mock out tests based on AWS infrastructure.

Home Page:http://docs.getmoto.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

S3: 'content-range' header not returned when a PartNumber is requested

vincer opened this issue · comments

GET/HEAD requests that request a specific object part via the partNumber query parameter, are "effectively ... a 'ranged' ... request" per the docs. So, their responses should have the content-range header just like a "standard" range request.

Here's code that inspects a partNumber=1 HEAD request for the content-range header.

:

def get_full_size(parsed: dict, **kwargs):
    content_range = parsed["ResponseMetadata"]["HTTPHeaders"]["content-range"]
    full_size = int(content_range.split("/")[1])
    print(f"full size: {full_size}")

client.meta.events.register(
    "after-call.s3.HeadObject",
    get_full_size,
    unique_id="get_full_size",
)
origin = client.head_object(
    Bucket=bucket, Key=key, PartNumber=1
)
client.meta.events.unregister(
    "after-call.s3.HeadObject",
    unique_id="get_full_size",
)

When using this against real S3, it works. With moto I get KeyError: 'content-range'.

As a side note: I do this so that I can get both the part size and the full size of an object in a single request and boto3 doesn't seem to natively expose that information even though it is there in the API response.