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.
@api
string
public function getPort() {
if (self::$trustedProxies) {
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;
}
}
return $this->server
->get('SERVER_PORT');
}