Permalink
Browse files

Putting the port in header Host, following RFC 2616 item 14.23. Fixes #…

  • Loading branch information...
1 parent 9f94d0d commit 9933b1ed209a047998edde5dbe6844659de63be3 @jrbasso jrbasso committed Jul 23, 2010
Showing with 38 additions and 2 deletions.
  1. +17 −1 cake/libs/http_socket.php
  2. +21 −1 cake/tests/cases/libs/http_socket.test.php
View
@@ -205,7 +205,23 @@ function request($request = array()) {
if (!empty($this->request['cookies'])) {
$cookies = $this->buildCookies($this->request['cookies']);
}
- $this->request['header'] = array_merge(array('Host' => $this->request['uri']['host']), $this->request['header']);
+ $Host = $this->request['uri']['host'];
+ $schema = '';
+ $port = 0;
+ if (isset($this->request['uri']['schema'])) {
+ $schema = $this->request['uri']['schema'];
+ }
+ if (isset($this->request['uri']['port'])) {
+ $port = $this->request['uri']['port'];
+ }
+ if (
+ ($schema === 'http' && $port != 80) ||
+ ($schema === 'https' && $port != 443) ||
+ ($port != 80 && $port != 443)
+ ) {
+ $Host .= ':' . $port;
+ }
+ $this->request['header'] = array_merge(compact('Host'), $this->request['header']);
}
if (isset($this->request['auth']['user']) && isset($this->request['auth']['pass'])) {
@@ -316,6 +316,25 @@ function testRequest() {
)
)
, 9 => array(
+ 'request' => array('method' => 'POST', 'uri' => 'http://www.cakephp.org:8080/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'))
+ , 'expectation' => array(
+ 'config' => array(
+ 'port' => 8080
+ , 'request' => array(
+ 'uri' => array(
+ 'port' => 8080
+ )
+ )
+ )
+ , 'request' => array(
+ 'uri' => array(
+ 'port' => 8080
+ )
+ , 'header' => "Host: www.cakephp.org:8080\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
+ )
+ )
+ )
+ , 10 => array(
'request' => array('method' => 'POST', 'uri' => 'https://www.cakephp.org/posts/add', 'body' => array('name' => 'HttpSocket-is-released', 'date' => 'today'))
, 'expectation' => array(
'config' => array(
@@ -332,10 +351,11 @@ function testRequest() {
'scheme' => 'https'
, 'port' => 443
)
+ , 'header' => "Host: www.cakephp.org\r\nConnection: close\r\nUser-Agent: CakePHP\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 38\r\n"
)
)
)
- , 10 => array(
+ , 11 => array(
'request' => array(
'method' => 'POST',
'uri' => 'https://www.cakephp.org/posts/add',

0 comments on commit 9933b1e

Please sign in to comment.