summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/http.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2000-07-19 23:43:49 +0000
committerdes <des@FreeBSD.org>2000-07-19 23:43:49 +0000
commitadc026dc209c4847c3f64c83a16d9aa614899737 (patch)
tree13585b48327db9525fdb2b2530a524c6f8b82f3d /lib/libfetch/http.c
parent4aa79112f9399dc33d0900418d7ded940d3b51db (diff)
downloadFreeBSD-src-adc026dc209c4847c3f64c83a16d9aa614899737.zip
FreeBSD-src-adc026dc209c4847c3f64c83a16d9aa614899737.tar.gz
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.
Diffstat (limited to 'lib/libfetch/http.c')
-rw-r--r--lib/libfetch/http.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index ce748c5..06dad22 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);
OpenPOWER on IntegriCloud