getUri(); if ('http' === $url->getScheme() && $this->wasRequestForwardedByHttps($request)) { $url = $url->withScheme('https'); } return $request->withUri($url); } private function wasRequestForwardedByHttps(RequestInterface $request): bool { $https = $request->hasHeader('x-forwarded-proto') && $request->getHeader('x-forwarded-proto')[0] === 'https'; $https = $https || ($request->hasHeader('x-forwarded-ssl') && $request->getHeader('x-forwarded-ssl')[0] === 'on'); return $https; } }