--- includes/common.inc	2007-01-03 07:33:26.000000000 -0600
+++ includes/common.inc	2007-01-03 07:34:37.000000000 -0600
@@ -486,6 +486,33 @@
       // Cookie:, followed by a comma-separated list of one or more cookies.
       $result->headers[$header] .= ','. trim($value);
     }
+    else if ($header == 'Transfer-Encoding' && $value == ' chunked') {
+      $result->headers[$header] = trim($value);
+
+      // RFC 2616, Section 3.6: The chunked encoding modifies the body of
+      // a message in order to transfer it as a series of chunks.
+      $do = TRUE;
+      $size = NULL;
+
+      while ($do) {
+        // suppress warnings with @ if offset not in string (past end)
+        $pos = @strpos($result->data, "\r\n", 0);
+
+        if (!($pos === FALSE) && $size === NULL) {
+          // we found CRLF, get len from hex
+          $size = hexdec(substr($result->data, 0, $pos));
+
+          // get the actual chunk-len, reset $result->data, $size
+          $return .= substr($result->data, $pos+2, $size);
+          $result->data = substr($result->data, ($pos+2) + $size);
+          $size = NULL;
+        }
+        else {
+          $do = FALSE;
+        }
+      }
+      $result->data = $return;
+    }
     else {
       $result->headers[$header] = trim($value);
     }
