HTTPRequest: Validate length before status code
authorDaniel Rudolf <daniel.rudolf@eifel-online.com>
Wed, 27 Feb 2013 11:38:27 +0000 (12:38 +0100)
committerDaniel Rudolf <daniel.rudolf@eifel-online.com>
Wed, 27 Feb 2013 11:38:27 +0000 (12:38 +0100)
wcfsetup/install/files/lib/util/HTTPRequest.class.php

index 52c7c16e6af1554492497e19b22f65cd9f98a2fc..54709f554e5c26e013bd45452609756952e370cf 100644 (file)
@@ -190,23 +190,32 @@ final class HTTPRequest {
                }
                $this->replyHeaders = $headers;
                
+               // get status code
                $statusLine = reset($this->replyHeaders);
                $regex = new Regex('^HTTP/1.(?:0|1) (\d{3})');
                if (!$regex->match($statusLine)) throw new SystemException("Unexpected status '".$statusLine."'");
                $matches = $regex->getMatches();
                $this->statusCode = $matches[1];
                
+               // validate length
+               if (isset($this->replyHeaders['Content-Length'])) {
+                       if (strlen($this->replyBody) != $this->replyHeaders['Content-Length']) {
+                               throw new SystemException('Body length does not match length given in header');
+                       }
+               }
+               
+               // validate status code
                switch ($this->statusCode) {
                        case '301':
                        case '302':
                        case '303':
                        case '307':
                                // redirect
-                               if ($this->options['maxDepth'] <= 0) throw new SystemException("Got redirect status '".$statusCode."', but recursion level is exhausted");
+                               if ($this->options['maxDepth'] <= 0) throw new SystemException("Got redirect status '".$this->statusCode."', but recursion level is exhausted");
                                
                                $newRequest = clone $this;
                                $newRequest->options['maxDepth']--;
-                               if ($statusCode != '307') {
+                               if ($this->statusCode != '307') {
                                        $newRequest->options['method'] = 'GET';
                                        $newRequest->postParameters = array();
                                        $newRequest->addHeader('Content-length', '');
@@ -235,13 +244,6 @@ final class HTTPRequest {
                                throw new SystemException("Got status '".$this->statusCode."' and I don't know how to handle it");
                        break;
                }
-               
-               // validate length
-               if (isset($this->replyHeaders['Content-Length'])) {
-                       if (strlen($this->replyBody) != $this->replyHeaders['Content-Length']) {
-                               throw new SystemException('Body length does not match length given in header');
-                       }
-               }
        }
        
        /**