Can GetObject API return less than expected?

0

Hi, I have a question while using the GetObject API in S3. https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html

As far as I understand, when requesting with a specified 'Range' parameter and the given range is correct, the 'Content-Range' and 'Content-Length' in the Response are expected to match the size of 'Range' in the parameter.

E.g. If the request is as follows: [Request] Range : bytes=0-9

The response should be as follows: [Response] Content-Range : bytes 0-9 Content-length : 10

  1. My question is, is there any possibility that the response returns less bytes than expected? (Suppose the range is valid)

E.g. If the request is as follows: [Request] Range : bytes=0-9

Is there any possibility that the response returns less bytes as follows ? : [Response] Content-Range : bytes 0-7 Content-length : 8

  1. If the case above is possible, what kind of response will I get? Is there any sample response for this case?

  2. If the case above is possible, can I get the cause of this in the response?

  3. Can a temporary network issue lead to the case above?

Thanks!

hs
asked 2 months ago217 views
1 Answer
0
  1. My question is, is there any possibility that the response returns less bytes than expected? (Suppose the range is valid)

Only if the range you ask for exceeds the actual object size. for example you ask for Range: bytes=0-9 but the response is only 8 bytes.

  1. If the case above is possible, what kind of response will I get? Is there any sample response for this case?

If the range you ask for exceeds the actual response size you will get a 206 Partial Content status code with the Content-Range header containing the actual returned size. following the example in answer 1: you will get Content-Range: bytes 0-7/8 (the value after the / provide the total size of the object being retrieved which should signal the client that there are no more parts)

If the starting byte of the requested range is beyond the total size of the object, S3 will return a 416 Requested Range Not Satisfiable response. e.g., if you send Range: bytes=10-19 but the response is only 8 bytes.

  1. If the case above is possible, can I get the cause of this in the response?

The cause is not directly indicated but you can infer it from the 206 Partial Content status code and the actual Content-Range value.

  1. Can a temporary network issue lead to the case above?

No, the content range being returned is based on the range being requested and is determined when the download starts. so if a network issue happens during the download it will not affect it.

profile pictureAWS
EXPERT
answered 2 months ago
  • "No, the content range being returned is based on the range being requested and is determined when the download starts. so if a network issue happens during the download it will not affect it." --> Does this mean that in case of network issue happening during the download, the 'content-range' is the same as the request, but the actual data received is less than the 'content-range' ?

  • Yes. just like would happen with any HTTP server (not just S3) and could also happen without specifying range. It's the recipient (client) responsibility to verify that the Content-Length header value matches the actual amount of bytes it received and to determine what to do in such case (e.g., to retry or to fail and show an error message).

  • Thanks! Just one last question. Is there any doc about your last comment ("It's the recipient (client) responsibility to verify that the Content-Length header value matches the actual amount of bytes it received and to determine what to do in such case") ?

  • This is generic for HTTP and not something specific to an AWS service.

    Quote from RFC7320 Section 3.3.3 Message Body Length:

    5. If a valid Content-Length header field is present without Transfer-Encoding, its decimal value defines the expected message body length in octets. If the sender closes the connection or the recipient times out before the indicated number of octets are received, the recipient MUST consider the message to be incomplete and close the connection.

    Usually a browser would show show an error on screen. for example Google Chrome would show ERR_CONNECTION_CLOSED like in the image here

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions