1
0
mirror of https://github.com/Rudloff/alltube.git synced 2024-06-20 06:46:40 +02:00

Cleaner way to build the canonical URL

This commit is contained in:
Pierre Rudloff 2020-10-22 00:28:36 +02:00
parent 68f2255fa0
commit 110bfc9ff1

View File

@ -13,6 +13,7 @@ use Alltube\Locale;
use Alltube\Middleware\CspMiddleware;
use Exception;
use Slim\Http\StatusCode;
use Slim\Http\Uri;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Throwable;
use Psr\Container\ContainerInterface;
@ -332,19 +333,11 @@ class FrontController extends BaseController
*/
private function getCanonicalUrl(Request $request)
{
/** @var Uri $uri */
$uri = $request->getUri();
$return = 'https://alltubedownload.net/';
$path = $uri->getPath();
if ($path != '/') {
$return .= $path;
}
$query = $uri->getQuery();
if (!empty($query)) {
$return .= '?' . $query;
}
return $return;
return $uri->withBasePath('')
->withHost('alltubedownload.net')
->withScheme('https');
}
}