From 453c5364c28dc86841582912a72a50608f68f12c Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Fri, 10 Dec 2010 10:38:49 -0200 Subject: [PATCH] Putting the auth and proxy data in request attribute after request. --- cake/libs/http_socket.php | 3 ++ cake/tests/cases/libs/http_socket.test.php | 55 ++++++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index a128e96ad..53e010874 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -246,6 +246,8 @@ class HttpSocket extends CakeSocket { $this->config['host'] = $host; } $this->_setProxy(); + $this->request['proxy'] = $this->_proxy; + $cookies = null; if (is_array($this->request['header'])) { @@ -276,6 +278,7 @@ class HttpSocket extends CakeSocket { $this->setAuthConfig('Basic', $this->request['uri']['user'], $this->request['uri']['pass']); } $this->_setAuth(); + $this->request['auth'] = $this->_auth; if (is_array($this->request['body'])) { $this->request['body'] = $this->_httpSerialize($this->request['body']); diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index a7410231f..aac957c0d 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -349,7 +349,7 @@ class HttpSocketTest extends CakeTestCase { 'host' => 'www.cakephp.org', 'port' => 80 ), - 'cookies' => array() + 'cookies' => array(), ) ), 'request' => array( @@ -369,7 +369,9 @@ 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' => "", - 'cookies' => array() + 'cookies' => array(), + 'proxy' => array(), + 'auth' => array() ) ) ), @@ -621,11 +623,11 @@ class HttpSocketTest extends CakeTestCase { } /** - * testRequestResultAsPointer method + * testRequestResultAsReference method * * @return void */ - public function testRequestResultAsPointer() { + public function testRequestResultAsReference() { $request = array('uri' => 'htpp://www.cakephp.org/'); $serverResponse = "HTTP/1.x 200 OK\r\nSet-Cookie: foo=bar\r\nDate: Mon, 16 Apr 2007 04:14:16 GMT\r\nServer: CakeHttp Server\r\nContent-Type: text/html\r\n\r\n

This is a cookie test!

"; $this->Socket->expects($this->at(1))->method('read')->will($this->returnValue($serverResponse)); @@ -652,6 +654,28 @@ class HttpSocketTest extends CakeTestCase { $this->assertEqual($this->Socket->request['raw'], $expected); $this->assertEqual($this->Socket->config['host'], 'proxy.server'); $this->assertEqual($this->Socket->config['port'], 123); + $expected = array( + 'host' => 'proxy.server', + 'port' => 123, + 'method' => null, + 'user' => null, + 'pass' => null + ); + $this->assertEqual($this->Socket->request['proxy'], $expected); + + $expected = "GET http://www.cakephp.org/bakery HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\n\r\n"; + $this->Socket->request('/bakery'); + $this->assertEqual($this->Socket->request['raw'], $expected); + $this->assertEqual($this->Socket->config['host'], 'proxy.server'); + $this->assertEqual($this->Socket->config['port'], 123); + $expected = array( + 'host' => 'proxy.server', + 'port' => 123, + 'method' => null, + 'user' => null, + 'pass' => null + ); + $this->assertEqual($this->Socket->request['proxy'], $expected); $expected = "GET http://www.cakephp.org/ HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nProxy-Authorization: Test mark.secret\r\n\r\n"; $this->Socket->setProxyConfig('proxy.server', 123, 'Test', 'mark', 'secret'); @@ -659,11 +683,34 @@ class HttpSocketTest extends CakeTestCase { $this->assertEqual($this->Socket->request['raw'], $expected); $this->assertEqual($this->Socket->config['host'], 'proxy.server'); $this->assertEqual($this->Socket->config['port'], 123); + $expected = array( + 'host' => 'proxy.server', + 'port' => 123, + 'method' => 'Test', + 'user' => 'mark', + 'pass' => 'secret' + ); + $this->assertEqual($this->Socket->request['proxy'], $expected); $this->Socket->setAuthConfig('Test', 'login', 'passwd'); $expected = "GET http://www.cakephp.org/ HTTP/1.1\r\nHost: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nProxy-Authorization: Test mark.secret\r\nAuthorization: Test login.passwd\r\n\r\n"; $this->Socket->request('http://www.cakephp.org/'); $this->assertEqual($this->Socket->request['raw'], $expected); + $expected = array( + 'host' => 'proxy.server', + 'port' => 123, + 'method' => 'Test', + 'user' => 'mark', + 'pass' => 'secret' + ); + $this->assertEqual($this->Socket->request['proxy'], $expected); + $expected = array( + 'Test' => array( + 'user' => 'login', + 'pass' => 'passwd' + ) + ); + $this->assertEqual($this->Socket->request['auth'], $expected); } /**