From c8453e5bf4f72e8941eea7746842719c5efd9c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Sun, 5 Mar 2017 12:06:45 +0000 Subject: [PATCH] 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 --- lib/libfetch/http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index bb509c182dd5..7e60f8b9118d 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -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;