From 4d28d5a2e40cd707187714f953ec44dd19b40beb Mon Sep 17 00:00:00 2001 From: Sascha Greuel Date: Wed, 5 Feb 2014 01:42:37 +0100 Subject: [PATCH] Added limit option --- .../files/lib/util/HTTPRequest.class.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/util/HTTPRequest.class.php b/wcfsetup/install/files/lib/util/HTTPRequest.class.php index ac47a3636c..f638c14b7f 100644 --- a/wcfsetup/install/files/lib/util/HTTPRequest.class.php +++ b/wcfsetup/install/files/lib/util/HTTPRequest.class.php @@ -124,6 +124,11 @@ final class HTTPRequest { $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)) { @@ -233,6 +238,7 @@ final class HTTPRequest { $remoteFile->puts($request); + $bodyLength = 0; $inHeader = true; $this->replyHeaders = array(); $this->replyBody = ''; @@ -249,6 +255,11 @@ final class HTTPRequest { } else { $this->replyBody .= $line; + $bodyLength = strlen($line); + + if (isset($this->options['maxLength']) && $bodyLength >= $this->options['maxLength']) { + break; + } } } @@ -279,7 +290,7 @@ final class HTTPRequest { $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'); } @@ -341,6 +352,16 @@ final class HTTPRequest { // 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"); -- 2.20.1