From f5d05d9ea99234da5dc6649769bbcf9a2dac9acd Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 1 Feb 2012 21:10:56 -0500 Subject: [PATCH] Fix https + query string requests. Using https + query strings would result in port 80 instead of the default https port. Fixes #2530 --- lib/Cake/Network/Http/HttpSocket.php | 16 ++++++++++++---- .../Test/Case/Network/Http/HttpSocketTest.php | 6 ++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index f18e043ac..9186e4105 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -93,9 +93,9 @@ class HttpSocket extends CakeSocket { 'timeout' => 30, 'request' => array( 'uri' => array( - 'scheme' => 'http', + 'scheme' => array('http', 'https'), 'host' => 'localhost', - 'port' => 80 + 'port' => array(80, 443) ), 'cookies' => array() ) @@ -522,11 +522,19 @@ class HttpSocket extends CakeSocket { $url = '/'; } if (is_string($url)) { + $scheme = $this->config['request']['uri']['scheme']; + if (is_array($scheme)) { + $scheme = $scheme[0]; + } + $port = $this->config['request']['uri']['port']; + if (is_array($port)) { + $port = $port[0]; + } if ($url{0} == '/') { - $url = $this->config['request']['uri']['host'] . ':' . $this->config['request']['uri']['port'] . $url; + $url = $this->config['request']['uri']['host'] . ':' . $port . $url; } if (!preg_match('/^.+:\/\/|\*|^\//', $url)) { - $url = $this->config['request']['uri']['scheme'] . '://' . $url; + $url = $scheme . '://' . $url; } } elseif (!is_array($url) && !empty($url)) { return false; diff --git a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php index bd580cd72..aee49df6c 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpSocketTest.php @@ -230,6 +230,7 @@ class HttpSocketTest extends CakeTestCase { $this->Socket->__construct('http://www.cakephp.org:23/'); $baseConfig['host'] = $baseConfig['request']['uri']['host'] = 'www.cakephp.org'; $baseConfig['port'] = $baseConfig['request']['uri']['port'] = 23; + $baseConfig['request']['uri']['scheme'] = 'http'; $baseConfig['protocol'] = getprotobyname($baseConfig['protocol']); $this->assertEquals($this->Socket->config, $baseConfig); @@ -914,11 +915,16 @@ class HttpSocketTest extends CakeTestCase { ->method('request') ->with(array('method' => 'GET', 'uri' => 'http://www.google.com/', 'version' => '1.0')); + $this->RequestSocket->expects($this->at(5)) + ->method('request') + ->with(array('method' => 'GET', 'uri' => 'https://secure.example.com/test.php?one=two')); + $this->RequestSocket->get('http://www.google.com/'); $this->RequestSocket->get('http://www.google.com/', array('foo' => 'bar')); $this->RequestSocket->get('http://www.google.com/', 'foo=bar'); $this->RequestSocket->get('http://www.google.com/?foo=bar', array('foobar' => '42', 'foo' => '23')); $this->RequestSocket->get('http://www.google.com/', null, array('version' => '1.0')); + $this->RequestSocket->get('https://secure.example.com/test.php', array('one' => 'two')); } /**