diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index e2355018b..0b2d00531 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -63,6 +63,7 @@ class HttpSocket extends CakeSocket { 'User-Agent' => 'CakePHP' ), 'raw' => null, + 'redirect' => false, 'cookies' => array() ); @@ -91,13 +92,13 @@ class HttpSocket extends CakeSocket { 'protocol' => 'tcp', 'port' => 80, 'timeout' => 30, - 'redirect' => false, 'request' => array( 'uri' => array( 'scheme' => 'http', 'host' => 'localhost', 'port' => 80 ), + 'redirect' => false, 'cookies' => array() ) ); @@ -378,8 +379,10 @@ class HttpSocket extends CakeSocket { } $this->config['request']['cookies'][$Host] = array_merge($this->config['request']['cookies'][$Host], $this->response->cookies); } - if($this->config['redirect'] && $this->response->isRedirect()) { + + if($this->request['redirect'] && $this->response->isRedirect()) { $request['uri'] = $this->response->getHeader('Location'); + $request['redirect'] = is_int($this->request['redirect']) ? $this->request['redirect'] - 1 : $this->request['redirect']; $this->response = $this->request($request); } diff --git a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php index 8f38e3f43..a7813b540 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php @@ -252,13 +252,13 @@ class HttpSocketTest extends CakeTestCase { 'protocol' => 'tcp', 'port' => 23, 'timeout' => 30, - 'redirect' => false, 'request' => array( 'uri' => array( 'scheme' => 'https', 'host' => 'www.cakephp.org', 'port' => 23 ), + 'redirect' => false, 'cookies' => array() ) ); @@ -277,13 +277,13 @@ class HttpSocketTest extends CakeTestCase { 'protocol' => 'tcp', 'port' => 80, 'timeout' => 30, - 'redirect' => false, 'request' => array( 'uri' => array( 'scheme' => 'http', 'host' => 'www.foo.com', 'port' => 80 ), + 'redirect' => false, 'cookies' => array() ) ); @@ -318,13 +318,13 @@ class HttpSocketTest extends CakeTestCase { 'protocol' => 'tcp', 'port' => 80, 'timeout' => 30, - 'redirect' => false, 'request' => array( 'uri' => array ( 'scheme' => 'http', 'host' => 'www.cakephp.org', 'port' => 80 ), + 'redirect' => false, 'cookies' => array() ) ), @@ -345,6 +345,7 @@ class HttpSocketTest extends CakeTestCase { 'line' => "GET /?foo=bar HTTP/1.1\r\n", 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n", 'raw' => "", + 'redirect' => false, 'cookies' => array(), 'proxy' => array(), 'auth' => array() @@ -722,19 +723,50 @@ class HttpSocketTest extends CakeTestCase { * * @return void */ - public function testRequestWithRedirect() { + public function testRequestWithRedirectAsTrue() { $request = array( - 'uri' => 'http://localhost/oneuri' + 'uri' => 'http://localhost/oneuri', + 'redirect' => true ); $serverResponse1 = "HTTP/1.x 302 Found\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\nLocation: http://localhost/anotheruri\r\n\r\n"; $serverResponse2 = "HTTP/1.x 200 OK\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n