diff options
author | fenner <fenner@FreeBSD.org> | 1998-10-26 02:39:21 +0000 |
---|---|---|
committer | fenner <fenner@FreeBSD.org> | 1998-10-26 02:39:21 +0000 |
commit | 1f7615e10ae633a40d231d083af293e2a6ac00d2 (patch) | |
tree | 79e37b30e495bdc02f6aa314467565127691af06 /usr.bin | |
parent | aa7fed94a8ccd9aa4b30fda6730aca1c6c5ffc17 (diff) | |
download | FreeBSD-src-1f7615e10ae633a40d231d083af293e2a6ac00d2.zip FreeBSD-src-1f7615e10ae633a40d231d083af293e2a6ac00d2.tar.gz |
If we know the content-length, only read that number of bytes from
the server. There exists a broken server which sends a few extra
garbage bytes in response to HTTP/1.1 requests.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/fetch/http.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/usr.bin/fetch/http.c b/usr.bin/fetch/http.c index ecade4e..24b63eb 100644 --- a/usr.bin/fetch/http.c +++ b/usr.bin/fetch/http.c @@ -26,7 +26,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: http.c,v 1.19 1998/07/12 09:07:36 se Exp $ + * $Id: http.c,v 1.20 1998/09/20 00:01:26 jkh Exp $ */ #include <sys/types.h> @@ -1036,18 +1036,29 @@ http_suck(struct fetch_state *fs, FILE *remote, FILE *local, { static char buf[BUFFER_SIZE]; ssize_t readresult, writeresult; + off_t remain = total_length; + + if (total_length == -1) + remain = 1; /*XXX*/ do { alarm(timo); readresult = fread(buf, 1, sizeof buf, remote); alarm(0); + /* + * If know the content-length, ignore anything more the + * the server chooses to send us. + */ + if (total_length != -1 && ((remain -= readresult) < 0)) + readresult += remain; + if (readresult == 0) return 0; display(fs, total_length, readresult); writeresult = fwrite(buf, 1, readresult, local); - } while (writeresult == readresult); + } while (writeresult == readresult && remain > 0); return 0; } |