Fix https + query string requests.

Using https + query strings would result in port 80 instead of the
default https port.

Fixes #2530
This commit is contained in:
mark_story 2012-02-01 21:10:56 -05:00
parent e697c68da5
commit f5d05d9ea9
2 changed files with 18 additions and 4 deletions

View file

@ -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;

View file

@ -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'));
}
/**