From 1f7615e10ae633a40d231d083af293e2a6ac00d2 Mon Sep 17 00:00:00 2001 From: fenner Date: Mon, 26 Oct 1998 02:39:21 +0000 Subject: 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. --- usr.bin/fetch/http.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'usr.bin/fetch') 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 @@ -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; } -- cgit v1.1