You are here

public function Request::getPort in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-foundation/Request.php \Symfony\Component\HttpFoundation\Request::getPort()

Returns the port on which the request is made.

This method can read the client port from the "X-Forwarded-Port" header when trusted proxies were set via "setTrustedProxies()".

The "X-Forwarded-Port" header must contain the client port.

If your reverse proxy uses a different header name than "X-Forwarded-Port", configure it via "setTrustedHeaderName()" with the "client-port" key.

Return value

string

1 call to Request::getPort()
Request::getHttpHost in vendor/symfony/http-foundation/Request.php
Returns the HTTP host being requested.

File

vendor/symfony/http-foundation/Request.php, line 955

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function getPort() {
  if ($this
    ->isFromTrustedProxy()) {
    if (self::$trustedHeaders[self::HEADER_CLIENT_PORT] && ($port = $this->headers
      ->get(self::$trustedHeaders[self::HEADER_CLIENT_PORT]))) {
      return $port;
    }
    if (self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && 'https' === $this->headers
      ->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO], 'http')) {
      return 443;
    }
  }
  if ($host = $this->headers
    ->get('HOST')) {
    if ($host[0] === '[') {
      $pos = strpos($host, ':', strrpos($host, ']'));
    }
    else {
      $pos = strrpos($host, ':');
    }
    if (false !== $pos) {
      return (int) substr($host, $pos + 1);
    }
    return 'https' === $this
      ->getScheme() ? 443 : 80;
  }
  return $this->server
    ->get('SERVER_PORT');
}