When attempting to access any range on an empty file, Werkzeug returns a 416 Requested Range Not Satisfiable error. Whilst this is perhaps reasonable, it is inconsistent with behaviour for non-empty files. For example, the range bytes=0-999999 on a small file, say 10 bytes in length, will succeed with a Content-Range: bytes 0-9/10 response header.
The issue is that Content-Range is inclusive, and so ostensibly the only way to succeed for an empty file would be to return the (invalid) response header Content-Range: bytes 0--1/0. As such, Werkzeug's behaviour is technically correct with respect to the specification, but I would argue it is undesirable/unexpected.
Two potential alternative approaches are:
- Respond with
Content-Range: bytes */0 to indicate an unknown range.
- 'Ignore' the range request in this case and return
200 OK.
Using curl -ir 0-0 against an empty file shows that different servers take different approaches. For sourtin.github.io/empty.txt, it gives a 416 error but responds with bytes */0, whereas for Apache/2.4.18 it gives 200 OK and ignores the range (i.e. approach 2).
Adding a special case is in its own way undesirable, but if either approach is acceptable I'm happy to submit an appropriate PR. I'd lean towards approach 2, personally.
When attempting to access any range on an empty file, Werkzeug returns a
416 Requested Range Not Satisfiableerror. Whilst this is perhaps reasonable, it is inconsistent with behaviour for non-empty files. For example, the rangebytes=0-999999on a small file, say 10 bytes in length, will succeed with aContent-Range: bytes 0-9/10response header.The issue is that
Content-Rangeis inclusive, and so ostensibly the only way to succeed for an empty file would be to return the (invalid) response headerContent-Range: bytes 0--1/0. As such, Werkzeug's behaviour is technically correct with respect to the specification, but I would argue it is undesirable/unexpected.Two potential alternative approaches are:
Content-Range: bytes */0to indicate an unknown range.200 OK.Using
curl -ir 0-0against an empty file shows that different servers take different approaches. Forsourtin.github.io/empty.txt, it gives a416error but responds withbytes */0, whereas forApache/2.4.18it gives200 OKand ignores the range (i.e. approach 2).Adding a special case is in its own way undesirable, but if either approach is acceptable I'm happy to submit an appropriate PR. I'd lean towards approach 2, personally.