symfony/symfony — Issue #3420: [Request] Support parsing "port" from HTTP_HOST, if exists
Author: ericclemmons
Created: 2012-02-23 03:14:15+00:00
State: open

When a user loads up `http://my-reporting-suite:8080/` (tunneled to `internal-networked-machine:80`), then you have the following:

```php
$_SERVER = array(
...
"HTTP_HOST" => "my-reporting-suite:8080",
"SERVER_PORT" => "80",
...
)
```

Routes should be built with the `HTTP_HOST`'s port (if defined) first, falling back to `SERVER_PORT`:

```php
// Symfony\Component\HttpFoundation\Request
public function getPort()
{
if (self::$trustProxy && $this->headers->has('X-Forwarded-Port')) {
return $this->headers->get('X-Forwarded-Port');
} else if ($hostPort = parse_url($this->server->get('HTTP_HOST'), PHP_URL_PORT)) {
return $hostPort;
} else {
return $this->server->get('SERVER_PORT');
}
}
```