Kaynağa Gözat

ZF-5520 adjusted regex to add ability to find headers like 'Location:http://www.google.com' (no space after :) in addition to the current 'Location: http://www.google.com'. Includes 1 unit test with two assertions.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22261 44c647ce-9c0f-0410-b52a-842ac1e357ba
wilmoore 15 yıl önce
ebeveyn
işleme
e531ac63af

+ 4 - 3
library/Zend/Http/Response.php

@@ -487,8 +487,8 @@ class Zend_Http_Response
     /**
     /**
      * Extract the headers from a response string
      * Extract the headers from a response string
      *
      *
-     * @param string $response_str
-     * @return array
+     * @param   string $response_str
+     * @return  array
      */
      */
     public static function extractHeaders($response_str)
     public static function extractHeaders($response_str)
     {
     {
@@ -507,7 +507,8 @@ class Zend_Http_Response
             $line = trim($line, "\r\n");
             $line = trim($line, "\r\n");
             if ($line == "") break;
             if ($line == "") break;
 
 
-            if (preg_match("|^([\w-]+):\s+(.+)|", $line, $m)) {
+            // Locate headers like 'Location: ...' and 'Location:...' (note the missing space)
+            if (preg_match("|^([\w-]+):\s*(.+)|", $line, $m)) {
                 unset($last_header);
                 unset($last_header);
                 $h_name = strtolower($m[1]);
                 $h_name = strtolower($m[1]);
                 $h_value = $m[2];
                 $h_value = $m[2];

+ 14 - 0
tests/Zend/Http/ResponseTest.php

@@ -162,6 +162,20 @@ class Zend_Http_ResponseTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($response->isRedirect(), 'Response is an error, but isRedirect() returned true');
         $this->assertFalse($response->isRedirect(), 'Response is an error, but isRedirect() returned true');
     }
     }
 
 
+    /**
+     * @group ZF-5520
+     */
+    public function test302LocationHeaderMatches()
+    {
+        $headerName  = 'Location';
+        $headerValue = 'http://www.google.com/ig?hl=en';
+        $response    = Zend_Http_Response::fromString($this->readResponse('response_302'));
+        $responseIis = Zend_Http_Response::fromString($this->readResponse('response_302_iis'));
+
+        $this->assertEquals($headerValue, $response->getHeader($headerName));
+        $this->assertEquals($headerValue, $responseIis->getHeader($headerName));
+    }
+
     public function test300isRedirect()
     public function test300isRedirect()
     {
     {
         $response = Zend_Http_Response::fromString($this->readResponse('response_302'));
         $response = Zend_Http_Response::fromString($this->readResponse('response_302'));

BIN
tests/Zend/Http/_files/response_302_iis