From: Tim Düsterhus Date: Mon, 24 Mar 2014 21:37:13 +0000 (+0100) Subject: Fix unchunking in HTTPRequest X-Git-Tag: 2.1.0_Alpha_1~974 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8f3e6138a212ebb1a7374163a5b61f88381a4b03;p=GitHub%2FWoltLab%2FWCF.git Fix unchunking in HTTPRequest --- diff --git a/wcfsetup/install/files/lib/util/HTTPRequest.class.php b/wcfsetup/install/files/lib/util/HTTPRequest.class.php index a0257f9ccd..3289cb9490 100644 --- a/wcfsetup/install/files/lib/util/HTTPRequest.class.php +++ b/wcfsetup/install/files/lib/util/HTTPRequest.class.php @@ -273,12 +273,6 @@ final class HTTPRequest { else { $chunkedTransferRegex = new Regex('(^|,)[ \t]*chunked[ \t]*$', Regex::CASE_INSENSITIVE); if (isset($this->replyHeaders['transfer-encoding']) && $chunkedTransferRegex->match(end($this->replyHeaders['transfer-encoding']))) { - // remove chunked from transfer-encoding - $this->replyHeaders['transfer-encoding'] = array_filter(array_map(function ($element) use ($chunkedTransferRegex) { - return $chunkedTransferRegex->replace($element, ''); - }, $this->replyHeaders['transfer-encoding']), 'trim'); - if (empty($this->replyHeaders['transfer-encoding'])) unset($this->replyHeaders['transfer-encoding']); - // last chunk finished if ($chunkLength === 0) { // read hex data and trash chunk-extension @@ -290,6 +284,12 @@ final class HTTPRequest { // clear remaining response while (!$remoteFile->gets()); + // remove chunked from transfer-encoding + $this->replyHeaders['transfer-encoding'] = array_filter(array_map(function ($element) use ($chunkedTransferRegex) { + return $chunkedTransferRegex->replace($element, ''); + }, $this->replyHeaders['transfer-encoding']), 'trim'); + if (empty($this->replyHeaders['transfer-encoding'])) unset($this->replyHeaders['transfer-encoding']); + // break out of main reading loop break; } @@ -297,13 +297,13 @@ final class HTTPRequest { else { $this->replyBody .= $line; $chunkLength -= strlen($line); - $bodyLength = +strlen($line); - $remoteFile->read(2); // CRLF + $bodyLength += strlen($line); + if ($chunkLength === 0) $remoteFile->read(2); // CRLF } } else { $this->replyBody .= $line; - $bodyLength = +strlen($line); + $bodyLength += strlen($line); } if (isset($this->options['maxLength']) && $bodyLength >= $this->options['maxLength']) {