don't error when asked for 0-based range on empty objects (#17708)

In a reverse proxying setup, a proxy in front of MinIO may attempt to
request objects in slices for enhanced cache efficiency. Since such a
a proxy cannot have prior knowledge of how large a requested resource is,
it usually sends a header of the form:

        Range: 0-$slice_size

... and, depending on the size of the resource, expects either:

- an empty response, if $resource_size == 0
- a full response, if $resource_size <= $slice_size
- a partial response, if $resource_size > $slice_size

Prior to this change, MinIO would respond 416 Range Not Satisfiable if a
client tried to request a range on an empty resource. This behavior is
technically consistent with RFC9110[1] – However, it renders sliced
reverse proxying, such as implemented in Nginx, broken in the case of
empty files. Nginx itself seems to break this convention to enable
"useful" responses in these cases, and MinIO should probably do that
too.

[1]: https://www.rfc-editor.org/rfc/rfc9110#byte.ranges
This commit is contained in:
flisk 2023-07-23 09:10:03 +02:00 committed by GitHub
parent 7764f4a8e3
commit 7e76d66184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,6 +59,9 @@ func (h *HTTPRangeSpec) GetLength(resourceSize int64) (rangeLength int64, err er
rangeLength = resourceSize rangeLength = resourceSize
} }
case h.Start == 0 && resourceSize == 0:
rangeLength = resourceSize
case h.Start >= resourceSize: case h.Start >= resourceSize:
return 0, errInvalidRange return 0, errInvalidRange