Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix https + query string requests.

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

Fixes #2530
  • Loading branch information...
commit f5d05d9ea99234da5dc6649769bbcf9a2dac9acd 1 parent e697c68
Mark Story markstory authored
16 lib/Cake/Network/Http/HttpSocket.php
View
@@ -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 @@ public function url($url = null, $uriTemplate = null) {
$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;
6 lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
View
@@ -230,6 +230,7 @@ public function testConstruct() {
$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 @@ public function testGet() {
->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'));
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.