X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FApp%2FRequest.php;h=d61303d5d729f410c8776aec4d534f04e53629b1;hb=c4870a16d4ffbd37d6c4f379abfe2d18cacb88ff;hp=c211dfe0e100cbf75d8c1c8f332cff7c29b98ab2;hpb=13783089e759ce111e5e5388cdfa8ecaf3ac9fb5;p=friendica.git diff --git a/src/App/Request.php b/src/App/Request.php index c211dfe0e1..d61303d5d7 100644 --- a/src/App/Request.php +++ b/src/App/Request.php @@ -1,6 +1,6 @@ remoteAddress; } + /** + * @return string The request ID of the current request + * + * Do always use this instead of $_SERVER['X_REQUEST_ID'] + */ + public function getRequestId(): string + { + return $this->requestId; + } + public function __construct(IManageConfigValues $config, array $server = []) { $this->remoteAddress = $this->determineRemoteAddress($config, $server); + $this->requestId = $server[static::DEFAULT_REQUEST_ID_HEADER] ?? System::createGUID(8, false); } /** @@ -58,6 +84,10 @@ class Request * Otherwise, $remoteAddress will be compared to $trustedProxy literally and the result * will be returned. * + * @param string $trustedProxy The current, trusted proxy to check + * @param string $remoteAddress The current remote IP address + * + * * @return boolean true if $remoteAddress matches $trustedProxy, false otherwise */ protected function matchesTrustedProxy(string $trustedProxy, string $remoteAddress): bool @@ -80,6 +110,9 @@ class Request * Checks if given $remoteAddress matches any entry in the given array $trustedProxies. * For details regarding what "match" means, refer to `matchesTrustedProxy`. * + * @param string[] $trustedProxies A list of the trusted proxies + * @param string $remoteAddress The current remote IP address + * * @return boolean true if $remoteAddress matches any entry in $trustedProxies, false otherwise */ protected function isTrustedProxy(array $trustedProxies, string $remoteAddress): bool @@ -94,8 +127,12 @@ class Request } /** + * Determines the remote address, if the connection came from a trusted proxy + * and `forwarded_for_headers` has been configured then the IP address + * specified in this header will be returned instead. + * * @param IManageConfigValues $config - * @param array $server + * @param array $server The $_SERVER array * * @return string */ @@ -105,7 +142,7 @@ class Request $trustedProxies = preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', $config->get('proxy', 'trusted_proxies', '')); if (\is_array($trustedProxies) && $this->isTrustedProxy($trustedProxies, $remoteAddress)) { - $forwardedForHeaders = preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', $config->get('proxy', 'forwarded_for_headers')) ?? static::ORDERED_FORWARD_FOR_HEADER; + $forwardedForHeaders = preg_split('/(\s*,*\s*)*,+(\s*,*\s*)*/', $config->get('proxy', 'forwarded_for_headers', static::DEFAULT_FORWARD_FOR_HEADER)); foreach ($forwardedForHeaders as $header) { if (isset($server[$header])) {