Constructor($server, $timeout); } function Constructor($server, $timeout = 15) { parent::Constructor($server, 80, $timeout); $this->header = &new Header(); $this->header->addHeader('Host', $server); $this->header->addHeader('Accept-Encoding', 'gzip'); $this->header->addHeader('Connection', 'close'); } function write($file) { $this->header->setFirstLine($this->method.' '.$file.' HTTP/1.1'); parent::write($this->header->makeRequest()); } function &readHeader() { $header = ''; do { $header .= $this->readln(); } while (!$this->eof() && substr($header, -4) != "\r\n\r\n"); if (substr($header, -4) != "\r\n\r\n") { trigger_error('no valid HTTP Response: '.$header); return false; } $headerObj = &new Header(); $headerObj->parseResponse($header); return $headerObj; } function readChunk() { $size = $this->nextChunkSize(); if (!$size || $size < 1) { return false; } $chunk = $this->read($size); $this->read(2); return $chunk; } function nextChunkSize() { $size = $this->readln(); return hexdec(substr($size, 0, -2)); } function readContent(&$header) { if ($header->inValue('transfer-encoding', 'chunked')) { $content = ''; while ($chunk = $this->readChunk()) { $content .= $chunk; } } else { $content = $this->readAll(); } return ($header->inValue('content-encoding', 'gzip') ? gzinflate(substr($content, 10)) : $content); } function download($path, &$file) { if (!$this->connect()) { return false; } $this->write($path); $header = &$this->readHeader(); if (!$header) { $this->close(); return false; } if ($header->exists('last-modified') && $file->is_uptodate(strtotime($header->getHeader('last-modified')))) { return true; } $content = $this->readContent($header); $this->close(); if (!$content) { return false; } return $file->write_once($content); } } ?>