$this->addHeader('User-Agent', "HTTP.PHP (HTTPRequest.class.php; WoltLab Community Framework/".WCF_VERSION."; ".WCF::getLanguage()->languageCode.")");
$this->addHeader('Accept', '*/*');
$this->addHeader('Accept-Language', WCF::getLanguage()->getFixedLanguageCode());
+
+ if (isset($this->options['maxLength'])) {
+ $this->addHeader('Range', 'bytes=0-'.$this->options['maxLength']);
+ }
+
if ($this->options['method'] !== 'GET') {
if (empty($this->files)) {
if (is_array($postParameters)) {
$remoteFile->puts($request);
+ $bodyLength = 0;
$inHeader = true;
$this->replyHeaders = array();
$this->replyBody = '';
}
else {
$this->replyBody .= $line;
+ $bodyLength = strlen($line);
+
+ if (isset($this->options['maxLength']) && $bodyLength >= $this->options['maxLength']) {
+ break;
+ }
}
}
$this->statusCode = $matches[1];
// validate length
- if (isset($this->replyHeaders['Content-Length'])) {
+ if (isset($this->replyHeaders['Content-Length']) && !isset($this->options['maxLength'])) {
if (strlen($this->replyBody) != $this->replyHeaders['Content-Length']) {
throw new SystemException('Body length does not match length given in header');
}
// we are fine
break;
+ case '206':
+ // check, if partial content was expected
+ if (!isset($this->headers['Range'])) {
+ throw new HTTPServerErrorException("Received unexpected status code '206' from server");
+ }
+ else if (!isset($this->replyHeaders['Content-Range'])) {
+ throw new HTTPServerErrorException("Content-Range is missing in reply header");
+ }
+ break;
+
case '401':
case '403':
throw new HTTPUnauthorizedException("Received status code '".$this->statusCode."' from server");