]> granicus.if.org Git - curl/commitdiff
Ignore content-length when chunked transfer-encoding is transfered.
authorDaniel Stenberg <daniel@haxx.se>
Wed, 3 Dec 2003 07:52:00 +0000 (07:52 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 3 Dec 2003 07:52:00 +0000 (07:52 +0000)
CHANGES
lib/transfer.c
lib/urldata.h

diff --git a/CHANGES b/CHANGES
index 14366a7924fe550b6872abe4c28e8d42089e89af..91e227f2d0395277164ef5fa53531334e75dd031 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,10 @@
                                   Changelog
 
 
+Daniel (3 December)
+- swalkaus at yahoo.com patched libcurl to ignore Content-Length: headers
+  when Tranfer-Encoding: chunked is used, as mandated by RFC2616.
+
 Daniel (2 December)
 - --ftp-pasv was added, which serves the only purpose of overriding a
   previously set --ftpport option. Starting now, --ftp-port is a recognized
index 5464d46a174d4659535b745eb3da62579cfaa4a6..0301167dc51d87abda0e42e89d2d9c59fa5da905 100644 (file)
@@ -206,6 +206,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
 
   fd_set *readfdp = k->readfdp;
   fd_set *writefdp = k->writefdp;
+  long contentlength;
   
   if((k->keepon & KEEP_READ) && !readfdp) {
     /* reading is requested, but no socket descriptor pointer was set */
@@ -474,8 +475,17 @@ CURLcode Curl_readwrite(struct connectdata *conn,
                      "Content-Length: 0" still prevents us from attempting to
                      read the (missing) response-body.
                   */
-                  if(-1 != conn->size)
+                  /* According to RFC2616 section 4.4, we MUST ignore
+                     Content-Length: headers if we are now receiving data
+                     using chunked Transfer-Encoding.
+                  */
+                  if(conn->bits.chunk)
+                    conn->size=-1;
+
+                  if(-1 != conn->size) {
+                    Curl_pgrsSetDownloadSize(data, conn->size);
                     conn->maxdownload = conn->size;
+                  }
                 }
                 /* If max download size is *zero* (nothing) we already
                    have nothing and can safely return ok now! */
@@ -590,14 +600,13 @@ CURLcode Curl_readwrite(struct connectdata *conn,
                info about the true size of the document we didn't get now. */
             if ((k->httpcode != 416) &&
                 checkprefix("Content-Length:", k->p) &&
-                sscanf (k->p+15, " %ld", &k->contentlength)) {
-              if (data->set.max_filesize && k->contentlength > 
+                sscanf (k->p+15, " %ld", &contentlength)) {
+              if (data->set.max_filesize && contentlength > 
                   data->set.max_filesize) {
                 failf(data, "Maximum file size exceeded");
                 return CURLE_FILESIZE_EXCEEDED;
               }
-              conn->size = k->contentlength;
-              Curl_pgrsSetDownloadSize(data, k->contentlength);
+              conn->size = contentlength;
             }
             /* check for Content-Type: header lines to get the mime-type */
             else if (checkprefix("Content-Type:", k->p)) {
@@ -1215,11 +1224,11 @@ CURLcode Curl_readwrite(struct connectdata *conn,
      * returning.
      */
 
-    if(!(data->set.no_body) && k->contentlength &&
-       (k->bytecount != k->contentlength) &&
+    if(!(data->set.no_body) && (conn->size != -1) &&
+       (k->bytecount != conn->size) &&
        !conn->newurl) {
       failf(data, "transfer closed with %d bytes remaining to read",
-            k->contentlength-k->bytecount);
+            conn->size - k->bytecount);
       return CURLE_PARTIAL_FILE;
     }
     else if(conn->bits.chunk && conn->proto.http->chunk.datasize) {
index f178015417ca1c0849dc3bee88736a412ee4afc5..834bcc6f3b024426597ea3fa3cc7121b89e47cf1 100644 (file)
@@ -306,7 +306,6 @@ struct ConnectBits {
 struct Curl_transfer_keeper {
   int bytecount;                /* total number of bytes read */
   int writebytecount;           /* number of bytes written */
-  long contentlength;           /* size of incoming data */
   struct timeval start;         /* transfer started at this time */
   struct timeval now;           /* current time */
   bool header;                 /* incoming data has HTTP header */