Fix partial requests (used by fetch -r) when the requested file is

already complete.

Since 416 is an error code, any Content-Range header in the response
would refer to the error message, not the requested document, so
relying on the value of size when we know we got a 416 is wrong.
Instead, just verify that offset == 0 and assume that we've reached
the end of the document (if offset > 0, we did not request a range,
and the server is screwing with us).  Note that we cannot distinguish
between reaching the end and going past it, but that is a flaw in the
protocol, not in the code, so we just have to assume that the caller
knows what it's doing.  A smart caller would request an offset
slightly before what it believes is the end and compare the result to
what is already in the file.

PR:		212065
Reported by:	mandree
MFC after:	3 weeks
This commit is contained in:
Dag-Erling Smørgrav 2017-03-05 12:06:45 +00:00
parent c1ad4beb32
commit c8453e5bf4

View File

@ -1925,7 +1925,7 @@ http_request_body(struct url *URL, const char *op, struct url_stat *us,
/* requested range not satisfiable */
if (conn->err == HTTP_BAD_RANGE) {
if (url->offset == size && url->length == 0) {
if (url->offset > 0 && url->length == 0) {
/* asked for 0 bytes; fake it */
offset = url->offset;
clength = -1;