--- transfer.c_old Tue Aug 17 16:36:07 2004 +++ transfer.c Wed Aug 18 09:06:50 2004 @@ -251,6 +251,7 @@ (!readfdp || FD_ISSET(conn->sockfd, readfdp))) { bool readdone = TRUE; + bool is_empty_data = FALSE; /* This is where we loop until we have read everything there is to read or we get a EWOULDBLOCK */ @@ -279,9 +280,11 @@ } didwhat |= KEEP_READ; + /* indicates data of zero size, i.e. empty file */ + is_empty_data = (nread == 0 && k->bodywrites == 0); /* NULL terminate, allowing string ops to be used */ - if (0 < nread) + if (0 < nread || is_empty_data) k->buf[nread] = 0; /* if we receive 0 or less here, the server closed the connection and @@ -922,9 +925,9 @@ /* This is not an 'else if' since it may be a rest from the header parsing, where the beginning of the buffer is headers and the end is non-headers. */ - if (k->str && !k->header && (nread > 0)) { + if (k->str && !k->header && (nread > 0 || is_empty_data)) { - if(0 == k->bodywrites) { + if(0 == k->bodywrites && !is_empty_data) { /* These checks are only made the first time we are about to write a piece of the body */ if(conn->protocol&PROT_HTTP) { @@ -975,7 +978,8 @@ } /* this is HTTP */ } /* this is the first time we write a body part */ - k->bodywrites++; + if (!is_empty_data) + k->bodywrites++; /* pass data to the debug function before it gets "dechunked" */ if(data->set.verbose) { @@ -1037,7 +1041,7 @@ Curl_pgrsSetDownloadCounter(data, k->bytecount); - if(!conn->bits.chunk && (nread || k->badheader)) { + if(!conn->bits.chunk && (nread || k->badheader || is_empty_data)) { /* If this is chunky transfer, it was already written */ if(k->badheader && !k->ignorebody) { @@ -1093,6 +1097,16 @@ } } /* if (! header and data to read ) */ + + if (is_empty_data) { + /* if we receive 0 here, the server closed the connection + and we are done*/ + if (nread == 0) { + k->keepon &= ~KEEP_READ; + FD_ZERO(&k->rkeepfd); + readdone = TRUE; + } + } } while(!readdone);