1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

Ignore content-length when chunked transfer-encoding is transfered.

This commit is contained in:
Daniel Stenberg 2003-12-03 07:52:00 +00:00
parent c79de8d86e
commit 0f4d042d3e
3 changed files with 21 additions and 9 deletions

View File

@ -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

View 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,9 +475,18 @@ 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! */
if(0 == conn->maxdownload)
@ -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) {

View 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 */