Ver Fonte

2009-05-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Supported segmented downloading with chunked transfer encoding and
	content-length.	
	* src/DownloadCommand.cc
	* src/HttpResponseCommand.cc
Tatsuhiro Tsujikawa há 16 anos atrás
pai
commit
3c877a9df4
3 ficheiros alterados com 16 adições e 4 exclusões
  1. 7 0
      ChangeLog
  2. 3 0
      src/DownloadCommand.cc
  3. 6 4
      src/HttpResponseCommand.cc

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2009-05-06  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Supported segmented downloading with chunked transfer encoding and
+	content-length.	
+	* src/DownloadCommand.cc
+	* src/HttpResponseCommand.cc
+
 2009-05-05  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Bump up version number to 1.3.3

+ 3 - 0
src/DownloadCommand.cc

@@ -165,6 +165,7 @@ bool DownloadCommand::executeInternal() {
   _requestGroup->getSegmentMan()->updateDownloadSpeedFor(peerStat);
 
   bool segmentComplete = false;
+  // Note that GrowSegment::complete() always returns false.
   if(_transferEncodingDecoder.isNull() && _contentEncodingDecoder.isNull()) {
     if(segment->complete()) {
       segmentComplete = true;
@@ -172,6 +173,8 @@ bool DownloadCommand::executeInternal() {
 	      !socket->wantRead() && !socket->wantWrite()) {
       segmentComplete = true;
     }
+  } else if(!_transferEncodingDecoder.isNull() && segment->complete()) {
+    segmentComplete = true;
   } else if((_transferEncodingDecoder.isNull() ||
 	     _transferEncodingDecoder->finished()) &&
 	    (_contentEncodingDecoder.isNull() ||

+ 6 - 4
src/HttpResponseCommand.cc

@@ -146,9 +146,10 @@ bool HttpResponseCommand::executeInternal()
     // update last modified time
     updateLastModifiedTime(httpResponse->getLastModifiedTime());
 
-    if(totalLength == 0 || httpResponse->isTransferEncodingSpecified() ||
-       shouldInflateContentEncoding(httpResponse)) {
-      // we ignore content-length when transfer-encoding is set
+    // If both transfer-encoding and total length is specified, we
+    // assume we can do segmented downloading
+    if(totalLength == 0 || shouldInflateContentEncoding(httpResponse)) {
+      // we ignore content-length when inflate is required
       dctx->setTotalLength(0);
       if(req->getMethod() == Request::METHOD_GET &&
 	 (totalLength != 0 ||
@@ -177,7 +178,8 @@ bool HttpResponseCommand::executeInternal()
 				   getTransferEncodingDecoder(httpResponse),
 				   getContentEncodingDecoder(httpResponse)));
     } else {
-      e->commands.push_back(createHttpDownloadCommand(httpResponse));
+      e->commands.push_back(createHttpDownloadCommand(httpResponse,
+						      getTransferEncodingDecoder(httpResponse)));
     }
     return true;
   }