From 87b41116ccce83eaf74eedc99b04fe02e12d0580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Wed, 19 Jul 2000 23:43:49 +0000 Subject: [PATCH] Don't try to skip to the requested offset if the server returns more data than requested. Instead, inform the caller of the real offset by modifying the offset field in the original struct url, and let him decide how to handle the situation. --- lib/libfetch/http.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index ce748c5c646f..06dad22ade4a 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -825,7 +825,7 @@ _http_request(struct url *URL, char *op, struct url_stat *us, char *flags) /* other headers */ _http_cmd(fd, "Host: %s:%d", host, url->port); _http_cmd(fd, "User-Agent: %s " _LIBFETCH_VER, __progname); - if (URL->offset) + if (url->offset) _http_cmd(fd, "Range: bytes=%lld-", url->offset); _http_cmd(fd, "Connection: close"); _http_cmd(fd, ""); @@ -950,19 +950,21 @@ _http_request(struct url *URL, char *op, struct url_stat *us, char *flags) goto ouch; } + /* too far? */ + if (offset > url->offset) { + _http_seterr(HTTP_PROTOCOL_ERROR); + goto ouch; + } + + /* report back real offset */ + URL->offset = offset; + /* wrap it up in a FILE */ if ((f = chunked ? _http_funopen(fd) : fdopen(fd, "r")) == NULL) { _fetch_syserr(); goto ouch; } - while (offset++ < url->offset) - if (fgetc(f) == EOF) { - _fetch_syserr(); - fclose(f); - f = NULL; - } - if (url != URL) fetchFreeURL(url);