Index: lib/http.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/http.c,v
retrieving revision 1.272
diff -u -r1.272 http.c
--- lib/http.c	11 May 2005 09:52:59 -0000	1.272
+++ lib/http.c	2 Jul 2005 22:55:30 -0000
@@ -96,6 +96,7 @@
 #include "memory.h"
 #include "select.h"
 #include "parsedate.h" /* for the week day and month names */
+#include "strtoofft.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
@@ -1076,7 +1077,7 @@
   int res;
   size_t nread;   /* total size read */
   int perline; /* count bytes per line */
-  bool keepon=TRUE;
+  int keepon=TRUE;
   ssize_t gotbytes;
   char *ptr;
   long timeout =
@@ -1085,6 +1086,7 @@
   char *host_port;
   curl_socket_t tunnelsocket = conn->sock[sockindex];
   send_buffer *req_buffer;
+  curl_off_t cl=0;
 
 #define SELECT_OK      0
 #define SELECT_ERROR   1
@@ -1215,6 +1217,13 @@
           int i;
 
           nread += gotbytes;
+
+          if(keepon > TRUE) {
+            cl -= gotbytes;
+            if(!cl)
+              break;
+          }
+          else
           for(i = 0; i < gotbytes; ptr++, i++) {
             perline++; /* amount of bytes in this line so far */
             if(*ptr=='\n') {
@@ -1242,7 +1251,19 @@
               if(('\r' == line_start[0]) ||
                  ('\n' == line_start[0])) {
                 /* end of response-headers from the proxy */
-                keepon=FALSE;
+                if(!cl)
+                  keepon = FALSE;
+                else {
+                  /* we must "eat" cl bytes now */
+                  keepon = 2;
+                  infof(data, "Ignore %" FORMAT_OFF_T
+                        " bytes of response-body\n", cl);
+                  cl -= (gotbytes - i);/* remove the remaining chunk of what
+                                          we already read */
+                  if(cl<=0)
+                    /* if the whole thing was already read, we are done! */
+                    keepon=FALSE;
+                }
                 break; /* breaks out of for-loop, not switch() */
               }
 
@@ -1257,6 +1278,10 @@
                 if(result)
                   return result;
               }
+              else if(checkprefix("Content-Length:", line_start)) {
+                cl = curlx_strtoofft(line_start + strlen("Content-Length:"),
+                                     NULL, 10);
+              }
               else if(2 == sscanf(line_start, "HTTP/1.%d %d",
                                   &subversion,
                                   &k->httpcode)) {
