diff options
author | Daniel Stenberg <daniel@haxx.se> | 2003-12-03 07:52:00 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2003-12-03 07:52:00 +0000 |
commit | 0f4d042d3e56fefe74a4f07ca5050a1f7efd5515 (patch) | |
tree | 0d985f8915124ba8e85cfd4103c7e166730da869 | |
parent | c79de8d86efd415ce8b8d67aadfa00981e3e0802 (diff) |
Ignore content-length when chunked transfer-encoding is transfered.
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | lib/transfer.c | 25 | ||||
-rw-r--r-- | lib/urldata.h | 1 |
3 files changed, 21 insertions, 9 deletions
@@ -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 diff --git a/lib/transfer.c b/lib/transfer.c index 5464d46a1..0301167dc 100644 --- a/lib/transfer.c +++ b/lib/transfer.c @@ -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) { diff --git a/lib/urldata.h b/lib/urldata.h index f17801541..834bcc6f3 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -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 */ |